The background of the project is to develop SPA single page application using Vue
Turtle nonsense, first on the mistake
Cannot find module 'webpack/bin/config-yargs'at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (D:\my\react-task\node_modules\webpack-dev-server\bin\webpack-dev-server.js:24:1) at Module._compile (module.js:409:26) at Object.Module._extensions.. js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) ......Copy the code
Well, I think the rest of the information can be put aside except for the top one (definitely not because I can’t understand it).
Encounter error how to do, search engine walks, cursory view looked a circle (to solve a problem first), of course error is solved finally.
The reason for the error
The mistake was made at the start of the project. I messed around with the command prompt before reporting the error, and now I forget what I did, but the result is to report the error above, which gives myself a ‘clap clap clap’.
Based on what I read online, there are two theories:
One is that webpack and webpack-dev-server versions don’t match. The other is that after Webpack4, config-yargs was put into webpack-CLI
What about their versions? A package.json file in the project root directory contains the description of the project and the imported dependencies, along with a devDependencies property where you can see the versions of the three template dependencies.
Here is mine (version changed) :
"webpack": "^ 3.8.0." "."webpack-bundle-analyzer": "^ 2.9.0"."webpack-dev-server": "^ 2.9.7".Copy the code
The solution
Start by opening CMD, navigate to your local project, and then try two solutions
- Webpack version install Webpack-CLI when 4 +, then update
npm install webpack-cli -D
npm update
Copy the code
I had a version of the webpack-CLI at 4:00pm and did the above and found that webpack-CLI failed or something, but still failed to start.
Uh-huh. It’s okay. I can handle it.
- Change the webpack and webpack-dev-server versions. Delete and then change the webpack and webpack-dev-server versions
// Uninstall version CNPM uninstall webpack -g CNPM uninstall -g webpack-dev-server // Install the specified version CNPM install [email protected] --save-dev CNPM install [email protected] - save - devCopy the code
(Don’t get hung up on -g, it doesn’t matter in my experiment.) Webpack3 and webpack-dev-server2 are compatible with each other.
Of course, if you still report an error at this point, MMMMMM ~. Delete node_modules (in the project root directory) and reinstall. To delete the folder, enter NMP Install in CMD.
If you can’t do that again, well, don’t do single-page apps.
over over over