我有一個Vue應用程序,我正在嘗試使用npm run start
運行,但是當我從PowerShell或VS Code終端運行該命令時,會出現以下錯誤:
> economyapp@0.1.0 start C:_codemyapp > npx vue-cli-service serve npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.org/vue-cli-service - Not found npm ERR! 404 npm ERR! 404 'vue-cli-service@latest' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url. npm ERR! A complete log of this run can be found in: npm ERR! C:UsersUserAppDataRoamingnpm-cache_logs2020-11-28T17_22_02_307Z-debug.log Install for [ 'vue-cli-service@latest' ] failed with code 1 npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! economyapp@0.1.0 start: `npx vue-cli-service serve` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the economyapp@0.1.0 start 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:UsersUserAppDataRoamingnpm-cache_logs2020-11-28T17_22_02_401Z-debug.log
當我從WSL中執行npm run start
命令時,它可以正常工作,但是當我對程式碼進行更改時,伺服器不會熱重載。我嘗試過卸載和重新安裝Vue CLI,並運行npm install
。
這是我的package.json檔案:
{ "name": "myapp", "version": "0.1.0", "private": true, "scripts": { "start": "npx vue-cli-service serve", "build": "npx vue-cli-service build", "test": "npx vue-cli-service test:unit", "lint": "npx vue-cli-service lint", "serve": "npx vue-cli-service serve" }, "dependencies": { "axios": "^0.21.0", "core-js": "^3.4.3", "lodash": "^4.17.15", "moment": "^2.24.0", "register-service-worker": "^1.6.2", "store2": "^2.11.1", "vue": "^3.0.0", "vue-router": "^3.1.3", "vuex": "^3.1.2" }, "devDependencies": { "@types/jest": "^24.0.19", "@typescript-eslint/eslint-plugin": "^2.28.0", "@typescript-eslint/parser": "^2.28.0", "@vue/cli-plugin-babel": "^4.1.0", "@vue/cli-plugin-eslint": "^4.1.0", "@vue/cli-plugin-pwa": "^4.1.0", "@vue/cli-plugin-router": "^4.1.0", "@vue/cli-plugin-typescript": "^4.3.1", "@vue/cli-plugin-vuex": "^4.1.0", "@vue/cli-service": "^4.2.3", "@vue/devtools": "^5.3.3", "@vue/eslint-config-prettier": "^5.0.0", "@vue/eslint-config-typescript": "^5.0.2", "@vue/test-utils": "1.0.0-beta.29", "eslint": "^6.0.0", "eslint-plugin-prettier": "^3.1.1", "eslint-plugin-vue": "^6.0.0", "lint-staged": "^9.4.3", "prettier": "^1.19.1", "typescript": "^3.8.3", "vue-template-compiler": "^2.6.10" }, "gitHooks": { "pre-commit": "lint-staged" }, "lint-staged": { "*.{js,vue,ts}": [ "vue-cli-service lint", "git add" ] } }
TL;DR: 執行
npm install
。vue-cli-service
由@vue/cli-service
在你的devDependencies中提供。因為你在npx
命令中沒有指定包,所以如果它必須在註冊表中查找,它會失敗。沒有npx
,你的npm
腳本將在node_modules/.bin
中尋找vue-cli-service
。你可以從npm
腳本移除npx
,你應該會得到與現在相同的結果。npx
找不到vue-cli-service
這個事實顯示你還沒執行npm install
。運行它,你的npm
腳本應該可以正常工作。如果不執行npm install
,一旦修復了這個問題,你肯定會遇到其他問題。如果出於某種原因,你希望
npm
腳本在不執行npm install
的情況下工作,你可以告訴npx
在登錄中找到二進位檔案的位置。將npm
腳本中的npx vue-cli-service
改為npx -p @vue/cli-service vue-cli-service
,這樣應該可以解決這個問題。但你一定會遇到其他問題。無論如何,你都應該運行npm install
。但要真正找到問題的根源,你需要弄清楚為什麼在WSL和非WSL環境中會有差異。我猜你在某個全域位置安裝了
@vue/cli-service
,只有WSL在你的PATH
中找到它,但這只是一個猜測。