Building for production... ERROR TypeError: Cannot read property ‘createHash‘ of undefined

created at 10-19-2021 views: 8

npm run build packaging error

Problem Description

  1. Because I recently updated my global webpack version, some old projects reported errors when installing;
  2. For an old project, the webpack version was not specified in devDependencies in package.json, which caused the project to fail during npm install. Solve it by specifying the webpack version as ^4.0.0;
  3. Later the project was modified and an error was reported when packaging:
Building for production... ERROR TypeError: Cannot read property 'createHash' of undefined

Final solution

npm install webpack@^4.5.0 -D

or

yarn add webpack@^4.5.0 -D

Updating the webpack version to version 4.5.0 can solve the problem. This is what I tried from @^4.0.0, @^4.1.0, @^4.2.0, @^4.5.0 again and again, really special Pit o(╥﹏╥)o

Summarize
Remember to add the local webpack version number to package.json when starting a project in the future, remember~~~

created at:10-19-2021
edited at: 10-19-2021: