npm run serve failed: regenerate node_modules/.bin

background

I am developing a front-end project recently. This project is copied from an old git project. When executing npm run serve, an error is reported that the vue-cli-service command cannot be found, but the original project is no problem with this operation .

Error: code:'MODULE_NOT_FOUND', there is a problem with xxx/node_modules/.bin/vue-cli-service.

The role of node_modules/.bin

Execute npm run, you can see that there are three executable script commands defined in the current package.json, npm 

Implementation process:

npm run-script (such as npm run serve)->Create a subshell environment in the current shell environment->Execute specific scripts in the subshell->Subshell first temporarily add node_modules/.bin to the PATH->Script in the subshell After the execution is complete, the PATH is restored to its previous appearance (does not affect the PATH in the parent shell)

This avoids affecting the global installation of npm.

Resolution process

First, look at whether there is vue-cli-service under node_modules/.bin. It does exist, but because it is directly from cp, the original soft link is gone.

Regenerate node_modules/.bin

# Erase the original directory 
RM -rf node_modules / .bin 
# recompile 
npm rebuild

As shown in the figure, the correct soft link file is regenerated.

You can try to execute it again: npm run serve, there will be no error. 

 

Blogger: Test to make money

Motto: Use testing to complete the original accumulation, and use investment to move towards financial freedom

csdn:https://blog.csdn.net/ccgshigao

博客园:https://www.cnblogs.com/qa-freeroad/

51cto:https://blog.51cto.com/14900374


Guess you like

Origin blog.51cto.com/14900374/2541219