1. 错误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 installnpm ERR! code ERESOLVEnpm ERR! ERESOLVE could not resolvenpm ERR!npm ERR! While resolving: extract-text-webpack-plugin@1.0.1npm ERR! Found: webpack@3.12.0npm ERR! node_modules/webpacknpm ERR! dev webpack@"^3.6.0" from the root project npm ERR! peer webpack@"2 || 3 || 4" from babel-loader@7.1.5npm ERR! node_modules/babel-loadernpm ERR! dev babel-loader@"^7.1.1" from the root projectnpm 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 extract-text-webpack-plugin@1.0.1npm ERR!npm ERR! Fix the upstream dependency conflict, or retrynpm ERR! this command with --force, or --legacy-peer-depsnpm 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
2.使用npm install --save --legacy-peer-deps
安装依赖
npm install --save --legacy-peer-deps
仍然出现错误,如下:
npm ERR! code 1npm ERR! path I:\fontend\2\mango-ui\node_modules\node-sassnpm ERR! command failednpm ERR! command C:\Windows\system32\cmd.exe /d /s /c C:\Users\ADMINI~1\AppData\Local\Temp\postinstall-b7425044.cmdnpm 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= --libsass_ldflags= --libsass_library=npm ERR! gyp info it worked if it ends with oknpm 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 node-gyp@3.8.0npm ERR! gyp info using node@16.17.1 | win32 | x64npm ERR! gyp verb command rebuild []npm ERR! gyp verb command clean []npm ERR! gyp verb clean removing "build" directorynpm 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 PATHnpm 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.15npm ERR! gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %jnpm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 16.17.1npm 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.1npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installednpm ERR! gyp verb install version is already installed, need to check "installVersion"npm ERR! gyp verb got "installVersion" 9npm ERR! gyp verb needs "installVersion" 9npm ERR! gyp verb install version is goodnpm ERR! gyp verb get node dir target node version installed: 16.17.1npm ERR! gyp verb build dir attempting to create "build" dir: I:\fontend\2\mango-ui\node_modules\node-sass\buildnpm ERR! gyp verb build dir "build" dir needed to be created? I:\fontend\2\mango-ui\node_modules\node-sass\buildnpm ERR! gyp verb find vs2017 Found installation at: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildToolsnpm ERR! gyp verb find vs2017 - Found Microsoft.VisualStudio.Component.Windows10SDK.19041npm ERR! gyp verb find vs2017 - Found Microsoft.VisualStudio.Component.VC.Tools.x86.x64npm ERR! gyp verb find vs2017 - Found Microsoft.VisualStudio.VC.MSBuild.Basenpm ERR! gyp verb find vs2017 - Using this installation with Windows 10 SDKnpm ERR! gyp verb find vs2017 using installation: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildToolsnpm ERR! gyp verb build/config.gypi creating config filenpm ERR! gyp verb build/config.gypi writing out config file: I:\fontend\2\mango-ui\node_modules\node-sass\build\config.gypinpm 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.gypinpm ERR! gyp verb common.gypi checking for gypi file: I:\fontend\2\mango-ui\node_modules\node-sass\common.gypinpm ERR! gyp verb gyp gyp format was not specified; forcing "msvs"npm ERR! gyp info spawn C:\Users\Administrator\.windows-build-tools\python27\python.exenpm 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 Releasenpm ERR! gyp verb architecture x64npm ERR! gyp verb node dev dir C:\Users\Administrator\.node-gyp\16.17.1npm ERR! gyp verb found first Solution file build/binding.slnnpm ERR! gyp verb using MSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\15.0\Bin\MSBuild.exenpm ERR! gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\15.0\Bin\MSBuild.exenpm 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 EXCEPTIONnpm ERR! gyp ERR! stack Error: spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\15.0\Bin\MSBuild.exe ENOENTnpm 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.19044npm 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-sassnpm ERR! gyp ERR! node -v v16.17.1npm ERR! gyp ERR! node-gyp -v v3.8.0npm 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! npm ERR! Build failed with error code: 7npm 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
版本不匹配导致。
3.单独安装node-sass
在网上查询到可以通过单独安装node-sass
解决问题,于是单独安装node-sass
,如下:
npm install -s node-sass@4.14.1
可以安装node-sass
,无错误输出。
运行程序npm run dev
,出现下面问题:
I:\fontend\2\mango-ui>npm run dev > mango-ui@1.0.0 dev> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序或批处理文件。
再次运行npm install --save --legacy-peer-deps
,错误依旧。
4.修改package.json,增加 "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> mango-ui@1.0.0 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
5. node
与node-sass
版本不匹配解决方法
经反复测试,当出现node版本不匹配问题时,可通过以下方法解决:
1. 删除旧的"node_modules"文件夹;2. 修改"package.json",在"devDependencies"中增加"node": "^13.14.0"依赖;3. npm install -s node-sass@4.14.1;4. npm install --save --legacy-peer-deps;5. npm run dev