npm ERR! code ERESOLVE
系統從win7
升級到win10
,之前的node
版本是13.14.0
,現在版本是16.17.1
。正常的vue
程式無法正常執行。從網上查詢得知"node-sass": "^4.14.1"
需要安裝python2.7
和vs_BuildTools
,於是安裝python2.7
和visual C++2019
,設定npm config set python C:\\Users\\Administrator\\.windows-build-tools\\python27\\python.exe
。
執行程式,仍然報錯。一氣之下刪除node_modules
資料夾,重新npm
安裝依賴包。
結果出現npm ERR! ERESOLVE could not resolve
錯誤,如下:
I:\fontend\2\mango-ui>npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR! dev webpack@"^3.6.0" from the root project
npm ERR! peer webpack@"2 || 3 || 4" from [email protected]
npm ERR! node_modules/babel-loader
npm ERR! dev babel-loader@"^7.1.1" from the root project
npm ERR! 8 more (file-loader, friendly-errors-webpack-plugin, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^1.9.11" from [email protected]
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See H:\tools\nodejs\node_cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! H:\tools\nodejs\node_cache\_logs\2022-10-09T13_31_26_126Z-debug-0.log
npm install --save --legacy-peer-deps
安裝依賴npm install --save --legacy-peer-deps
仍然出現錯誤,如下:
npm ERR! code 1
npm ERR! path I:\fontend\2\mango-ui\node_modules\node-sass
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c C:\Users\ADMINI~1\AppData\Local\Temp\postinstall-b7425044.cmd
npm ERR! Building: D:\Program Files\nodejs\node.exe I:\fontend\2\mango-ui\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --l
ibsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli 'D:\\Program Files\\nodejs\\node.exe',
npm ERR! gyp verb cli 'I:\\fontend\\2\\mango-ui\\node_modules\\node-gyp\\bin\\node-gyp.js',
npm ERR! gyp verb cli 'rebuild',
npm ERR! gyp verb cli '--verbose',
npm ERR! gyp verb cli '--libsass_ext=',
npm ERR! gyp verb cli '--libsass_cflags=',
npm ERR! gyp verb cli '--libsass_ldflags=',
npm ERR! gyp verb cli '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb check python checking for Python executable "C:\Users\Administrator\.windows-build-tools\python27\python.exe" in the PATH
npm ERR! gyp verb `which` succeeded C:\Users\Administrator\.windows-build-tools\python27\python.exe C:\Users\Administrator\.windows-build-tools\python27\python.exe
npm ERR! gyp verb check python version `C:\Users\Administrator\.windows-build-tools\python27\python.exe -c "import sys; print "2.7.15
npm ERR! gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.17.1
npm ERR! gyp verb command install [ '16.17.1' ]
npm ERR! gyp verb install input version string "16.17.1"
npm ERR! gyp verb install installing version: 16.17.1
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 16.17.1
npm ERR! gyp verb build dir attempting to create "build" dir: I:\fontend\2\mango-ui\node_modules\node-sass\build
npm ERR! gyp verb build dir "build" dir needed to be created? I:\fontend\2\mango-ui\node_modules\node-sass\build
npm ERR! gyp verb find vs2017 Found installation at: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
npm ERR! gyp verb find vs2017 - Found Microsoft.VisualStudio.Component.Windows10SDK.19041
npm ERR! gyp verb find vs2017 - Found Microsoft.VisualStudio.Component.VC.Tools.x86.x64
npm ERR! gyp verb find vs2017 - Found Microsoft.VisualStudio.VC.MSBuild.Base
npm ERR! gyp verb find vs2017 - Using this installation with Windows 10 SDK
npm ERR! gyp verb find vs2017 using installation: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
npm ERR! gyp verb build/config.gypi creating config file
npm ERR! gyp verb build/config.gypi writing out config file: I:\fontend\2\mango-ui\node_modules\node-sass\build\config.gypi
npm ERR! (node:3484) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp verb config.gypi checking for gypi file: I:\fontend\2\mango-ui\node_modules\node-sass\config.gypi
npm ERR! gyp verb common.gypi checking for gypi file: I:\fontend\2\mango-ui\node_modules\node-sass\common.gypi
npm ERR! gyp verb gyp gyp format was not specified; forcing "msvs"
npm ERR! gyp info spawn C:\Users\Administrator\.windows-build-tools\python27\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'I:\\fontend\\2\\mango-ui\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'msvs',
npm ERR! gyp info spawn args '-G',
npm ERR! gyp info spawn args 'msvs_version=2015',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'I:\\fontend\\2\\mango-ui\\node_modules\\node-sass\\build\\config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'I:\\fontend\\2\\mango-ui\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args 'C:\\Users\\Administrator\\.node-gyp\\16.17.1\\include\\node\\common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=C:\\Users\\Administrator\\.node-gyp\\16.17.1',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=I:\\fontend\\2\\mango-ui\\node_modules\\node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=C:\\Users\\Administrator\\.node-gyp\\16.17.1\\<(target_arch)\\node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=I:\\fontend\\2\\mango-ui\\node_modules\\node-sass',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'I:\\fontend\\2\\mango-ui\\node_modules\\node-sass\\build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp verb command build []
npm ERR! gyp verb build type Release
npm ERR! gyp verb architecture x64
npm ERR! gyp verb node dev dir C:\Users\Administrator\.node-gyp\16.17.1
npm ERR! gyp verb found first Solution file build/binding.sln
npm ERR! gyp verb using MSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
npm ERR! gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args 'build/binding.sln',
npm ERR! gyp info spawn args '/nologo',
npm ERR! gyp info spawn args '/p:Configuration=Release;Platform=x64'
npm ERR! gyp info spawn args ]
npm ERR! gyp ERR! UNCAUGHT EXCEPTION
npm ERR! gyp ERR! stack Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\15.0\Bin\MSBuild.exe ENOENT
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
npm ERR! gyp ERR! stack at onErrorNT (node:internal/child_process:478:16)
npm ERR! gyp ERR! stack at processTicksAndRejections (node:internal/process/task_queues:83:21)
npm ERR! gyp ERR! System Windows_NT 10.0.19044
npm ERR! gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "I:\\fontend\\2\\mango-ui\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_
ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd I:\fontend\2\mango-ui\node_modules\node-sass
npm ERR! gyp ERR! node -v v16.17.1
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! This is a bug in `node-gyp`.
npm ERR! gyp ERR! Try to update node-gyp and file an Issue if it does not help:
npm ERR! gyp ERR! <https://github.com/nodejs/node-gyp/issues>
npm ERR! Build failed with error code: 7
npm ERR! A complete log of this run can be found in:
npm ERR! H:\tools\nodejs\node_cache\_logs\2022-10-09T14_15_40_435Z-debug-0.log
檢視錯誤,ERR
最早出現仍然是node-sass
,猜測仍然是node
版本不匹配導致。
node-sass
在網上查詢到可以通過單獨安裝node-sass
解決問題,於是單獨安裝node-sass
,如下:
npm install -s [email protected]
可以安裝node-sass
,無錯誤輸出。
執行程式npm run dev
,出現下面問題:
I:\fontend\2\mango-ui>npm run dev
> [email protected] dev
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
'webpack-dev-server' 不是內部或外部命令,也不是可執行的程式或批次檔。
再次執行npm install --save --legacy-peer-deps
,錯誤依舊。
"node": "^13.14.0"
在網上查詢了好久都找不到解決方法,考慮到錯誤原因是node
版本升級問題。於是自己嘗試將"node": "^13.14.0"
新增到package.json
中"devDependencies"
項下。
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"mockjs": "^1.0.1-beta3",
"node": "^13.14.0",
"node-notifier": "^5.1.2",
"node-sass": "^4.14.1",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"sass-loader": "^7.3.1",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"style-loader": "^3.1.0",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^4.1.1",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
再次執行npm install --save --legacy-peer-deps
,無錯誤,且node_modules
中會下載node13.14.0.exe
。
執行npm run dev
,程式正常執行,如下:
I:\fontend\2\mango-ui>npm run dev
> [email protected] dev
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
95% emitting
DONE Compiled successfully in 18305ms 下午10:43:07
I Your application is running here: http://localhost:8080
node
與node-sass
版本不匹配解決方法經反覆測試,當出現node版本不匹配問題時,可通過以下方法解決:
1. 刪除舊的"node_modules"資料夾;
2. 修改"package.json",在"devDependencies"中增加"node": "^13.14.0"依賴;
3. npm install -s [email protected];
4. npm install --save --legacy-peer-deps;
5. npm run dev