'How to fix 'Cannot find module vue-cli-service.js'?
I'm setting up a new Vue project and when I'm running the command npm run serve into CMD, the following error appears:
Error: Cannot find module 'C:\Users\Bram Wicherink\@vue\cli-service\bin\vue-cli-service.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] serve: 'vue-cli-service serve'
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Bram Wicherink\AppData\Roaming\npm-cache\_logs\2019-09-13T14_03_01_676Z-debug.log
What do I have to do?
I have read the logs, I uninstalled and reinstalled NPM, Vue, Node.js and read some background information on Google, but nothing worked.
Solution 1:[1]
In my case (Windows), the node_modules\.bin\vue-cli-service.cmd was failing because one of my parent folders had an ampersand character which breaks %~dp0
Solution 2:[2]
This is just from my experience concerning this issue using multiple disks on a windows 10 development environment: I have a work machine using multiple hard-drives: one split for the OS and another for file storage. The vue-cli install by following(droning off) the docs by default installed to my primary disk (C:), however attempting to configure -of which was successful- but running from the secondary disk (D:) resulted in the same error. Running vue-cli commands to create and serve the vue js app (the crux of the issue here) on the primary disk (C:) resolved this issue for me.
Please note: this is not an intact solution but rather observation from my end, even if it may sound trivial.
Solution 3:[3]
I had a clean_bins.cmd script run in my project which searches for all /bin/ folders and removes it. After I run that script I had the same problem with vue.
To solve the issue just clean the /node_modules/ folder and run npm install.
Solution 4:[4]
I had an ampersand character in my parent folder, I took 2 hours to try almost everything... Just delete the "&" and then worked.
Solution 5:[5]
Solution
Removing & from any of the folder's name or sub-folders inside which your project lies will resolve the issue.
Explanation
The & symbol in any of the folders or ancestor/parent folder's name inside which your project lies will initiate a vue-cli execution issue as & is a special character.
The %~dp0 (that’s a zero) variable when referenced within a Windows batch file will expand to the drive letter and path of that batch file.
The variables %0-%9 refer to the command line parameters of the batch file. %1-%9 refer to command-line arguments after the batch file name. %0 refers to the batch file itself.
If you follow the percent character (%) with a tilde character (~), you can insert a modifier(s) before the parameter number to alter the way the variable is expanded. The d modifier expands to the drive letter and the p modifier expands to the path of the parameter.
Example: Let’s say you have a directory on C: called bat_files, and in that directory is a file called example.bat. In this case, %~dp0 (combining the d and p modifiers) will expand to C:\bat_files\.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | 6footunder |
| Solution 2 | Prav |
| Solution 3 | ADM-IT |
| Solution 4 | Jason |
| Solution 5 | Harsh Shukla |
