Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用vue-cli新建项目,启动时报错:Error: Cannot find module 'E:\@vue\cli-service\bin\vue-cli-service.js' #5420

Closed
wanghuan19961020 opened this issue Apr 24, 2020 · 6 comments

Comments

@wanghuan19961020
Copy link

Version

4.3.1

Environment info

win10

Steps to reproduce

问题复现

  1. 使用vue create test-demo创建项目test-demo,自定义配置如下:
    image
  2. 进入test-demo目录,启动项目npm run serve,出现以下报错:
    image

错误原因分析

  • 仔细看报错提示Error: Cannot find module 'E:\@vue\cli-service\bin\vue-cli-service.js'
  • 发现事实上在E盘下的确没有这个模块
  • 这个模块正确的路径应该是在
E:\[项目文件]\node_models\.bin\@vue\cli-service\bin\vue-cli-service.js'
  • 思考是不是在启动服务的时候,配置文件出错导致没有正确的找到模块路径
  • 然后将node_modules/.bin/vue-cli-service.cmd文件的内容修改为:
@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\@vue\cli-service\bin\vue-cli-service.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  "%~dp0\..\@vue\cli-service\bin\vue-cli-service.js" %*
)
  • 项目可以正常运行了
  • node_modules/.bin/vue-cli-service.cmd文件的原本内容:
@ECHO off
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

"%_prog%"  "%dp0%\..\@vue\cli-service\bin\vue-cli-service.js" %*
ENDLOCAL
EXIT /b %errorlevel%
:find_dp0
SET dp0=%~dp0
EXIT /b

请问这个是什么原因导致的?有没有什么彻底的解决方法?

What is expected?

npm run serve可以正常启动项目,不会报错

What is actually happening?

npm run serve无法正常启动项目,报错Error: Cannot find module 'E:@VUE\cli-service\bin\vue-cli-service.js'

@vyrru5
Copy link

vyrru5 commented Apr 25, 2020

the same, on win10 & macOS
node -v 14
npm 6.14.4
@vue/cli 4.3.1

@fangbinwei
Copy link
Collaborator

fangbinwei commented Apr 28, 2020

The error caused by the & of path E:\webpack&vuecli&vue-router&vuex

and node_modules/.bin/vue-cli-service.cmd is generated by npm

@wanghuan19961020
Copy link
Author

The error caused by the & of path E:\webpack&vuecli&vue-router&vuex

and node_modules/.bin/vue-cli-service.cmd is generated by npm

Is it because of the environment or configuration?How to deal with this situation?

@fangbinwei
Copy link
Collaborator

fangbinwei commented Apr 29, 2020

@wanghuan19961020 I am not familiar with the syntax of .cmd. I can only suggest don't use & in your directory on windows 10. Maybe someone else can help you.

@wanghuan19961020
Copy link
Author

@fangbinwei Thank you

@haoqunjiang
Copy link
Member

Seems related to this bug npm/cmd-shim#45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants