运行 npm install 时 node-sass 出错
Posted
技术标签:
【中文标题】运行 npm install 时 node-sass 出错【英文标题】:Error with node-sass when running npm install 【发布时间】:2021-11-17 13:38:11 【问题描述】:每当我在 vue.js 项目上运行 npm install 时,我都会收到以下错误
5769 error code 1
5770 error path /*my path*/node_modules/node-sass
5771 error command failed
5772 error command sh -c node scripts/install.js
5773 error /*my path*/node_modules/request/index.js:30
5773 error if (options !== null && typeof op
5773 error
5773 error
5773 error SyntaxError: Unexpected end of input
5773 error at Object.compileFunction (node:vm:352:18)
5773 error at wrapSafe (node:internal/modules/cjs/loader:1031:15)
5773 error at Module._compile (node:internal/modules/cjs/loader:1065:27)
5773 error at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
5773 error at Module.load (node:internal/modules/cjs/loader:981:32)
5773 error at Function.Module._load (node:internal/modules/cjs/loader:822:12)
5773 error at Module.require (node:internal/modules/cjs/loader:1005:19)
5773 error at require (node:internal/modules/cjs/helpers:102:18)
5773 error at Object.<anonymous> (/*my path*/node_modules/node-sass/scripts/install.js:10:13)
5773 error at Module._compile (node:internal/modules/cjs/loader:1101:14)
5774 verbose exit 1
我尝试过重新安装 node 和 npm,但它似乎总是在 node-sass 上停止。
npm install
在我所有的 laravel 项目中运行良好。这只发生在我最近提取的两个项目上,几乎完全是 Vue.js 和 typescript,所以我不确定这是否可能是问题。
编辑:我尝试删除本地版本,从 github 拉取并再次运行 npm install
并收到此错误。这是一个巨大的错误,所以我不得不删除一大块以将其放入帖子中。
2863 error code 1
2864 error path /*my path*/node_modules/node-sass
2865 error command failed
2866 error command sh -c node scripts/build.js
2867 error Building: /opt/homebrew/Cellar/node/16.10.0/bin/node /Users/scott/Dev/KPro/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
2867 error c++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DLIBSASS_VERSION="3.5.5"' -I/Users/scott/.node-gyp/16.10.0/include/node -I/Users/scott/.node-gyp/16.10.0/src -I/Users/scott/.node-gyp/16.10.0/deps/openssl/config -I/Users/scott/.node-gyp/16.10.0/deps/openssl/openssl/include -I/Users/scott/.node-gyp/16.10.0/deps/uv/include -I/Users/scott/.node-gyp/16.10.0/deps/zlib -I/Users/scott/.node-gyp/16.10.0/deps/v8/include -I../src/libsass/include -O3 -gdwarf-2 -mmacosx-version-min=10.7 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++11 -stdlib=libc++ -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/libsass/src/libsass/src/ast.o.d.raw -c -o Release/obj.target/libsass/src/libsass/src/ast.o ../src/libsass/src/ast.cpp
2867 error c++ '-DNODE_GYP_MODULE_NAME=libsass' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DLIBSASS_VERSION="3.5.5"' -I/Users/scott/.node-gyp/16.10.0/include/node -I/Users/scott/.node-gyp/16.10.0/src -I/Users/scott/.node-gyp/16.10.0/deps/openssl/config -I/Users/scott/.node-gyp/16.10.0/deps/openssl/openssl/include -I/Users/scott/.node-gyp/16.10.0/deps/uv/include -I/Users/scott/.node-gyp/16.10.0/deps/zlib -I/Users/scott/.node-gyp/16.10.0/deps/v8/include -I../src/libsass/include -O3 -gdwarf-2 -mmacosx-version-min=10.7 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=c++11 -stdlib=libc++ -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/libsass/src/libsass/src/ast_fwd_decl.o.d.raw -c -o Release/obj.target/libsass/src/libsass/src/ast_fwd_decl.o ../src/libsass/src/ast_fwd_decl.cpp
2868 error gyp info it worked if it ends with ok
2868 error gyp verb cli [
2868 error gyp verb cli '/opt/homebrew/Cellar/node/16.10.0/bin/node',
2868 error gyp verb cli '/*my path*/node_modules/node-gyp/bin/node-gyp.js',
2868 error gyp verb cli 'rebuild',
2868 error gyp verb cli '--verbose',
2868 error gyp verb cli '--libsass_ext=',
2868 error gyp verb cli '--libsass_cflags=',
2868 error gyp verb cli '--libsass_ldflags=',
2868 error gyp verb cli '--libsass_library='
2868 error gyp verb cli ]
2868 error gyp info using node-gyp@3.8.0
2868 error gyp info using node@16.10.0 | darwin | arm64
2868 error gyp verb command rebuild []
2868 error gyp verb command clean []
2868 error gyp verb clean removing "build" directory
2868 error gyp verb command configure []
2868 error gyp verb check python checking for Python executable "python2" in the PATH
2868 error gyp verb `which` succeeded python2 /usr/bin/python2
2868 error gyp verb check python version `/usr/bin/python2 -c "import sys; print "2.7.16
2868 error gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
2868 error gyp verb get node dir no --target version specified, falling back to host node version: 16.10.0
2868 error gyp verb command install [ '16.10.0' ]
2868 error gyp verb install input version string "16.10.0"
2868 error gyp verb install installing version: 16.10.0
2868 error gyp verb install --ensure was passed, so won't reinstall if already installed
2868 error gyp verb install version is already installed, need to check "installVersion"
2868 error gyp verb got "installVersion" 9
2868 error gyp verb needs "installVersion" 9
2868 error gyp verb install version is good
2868 error gyp verb get node dir target node version installed: 16.10.0
2868 error gyp verb build dir attempting to create "build" dir: /Users/scott/Dev/KPro/node_modules/node-sass/build
2868 error gyp verb build dir "build" dir needed to be created? /Users/scott/Dev/KPro/node_modules/node-sass/build
2868 error gyp verb build/config.gypi creating config file
2868 error gyp verb build/config.gypi writing out config file: /*my path*/node_modules/node-sass/build/config.gypi
2868 error (node:57324) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
2868 error (Use `node --trace-deprecation ...` to show where the warning was created)
2868 error gyp verb config.gypi checking for gypi file: /*my path*/node_modules/node-sass/config.gypi
2868 error gyp verb common.gypi checking for gypi file: /*my path*/node_modules/node-sass/common.gypi
2868 error gyp verb gyp gyp format was not specified; forcing "make"
2868 error gyp info spawn /usr/bin/python2
2868 error gyp info spawn args [
2868 error gyp info spawn args '/*my path*/node_modules/node-gyp/gyp/gyp_main.py',
2868 error gyp info spawn args 'binding.gyp',
2868 error gyp info spawn args '-f',
2868 error gyp info spawn args 'make',
2868 error gyp info spawn args '-I',
2868 error gyp info spawn args '/*my path*/node_modules/node-sass/build/config.gypi',
2868 error gyp info spawn args '-I',
2868 error gyp info spawn args '/*my path*/node_modules/node-gyp/addon.gypi',
2868 error gyp info spawn args '-I',
2868 error gyp info spawn args '/Users/scott/.node-gyp/16.10.0/include/node/common.gypi',
2868 error gyp info spawn args '-Dlibrary=shared_library',
2868 error gyp info spawn args '-Dvisibility=default',
2868 error gyp info spawn args '-Dnode_root_dir=/Users/scott/.node-gyp/16.10.0',
2868 error gyp info spawn args '-Dnode_gyp_dir=/Users/scott/Dev/KPro/node_modules/node-gyp',
2868 error gyp info spawn args '-Dnode_lib_file=/Users/scott/.node-gyp/16.10.0/<(target_arch)/node.lib',
2868 error gyp info spawn args '-Dmodule_root_dir=/*my path*/node_modules/node-sass',
2868 error gyp info spawn args '-Dnode_engine=v8',
2868 error gyp info spawn args '--depth=.',
2868 error gyp info spawn args '--no-parallel',
2868 error gyp info spawn args '--generator-output',
2868 error gyp info spawn args 'build',
2868 error gyp info spawn args '-Goutput_dir=.'
2868 error gyp info spawn args ]
2868 error gyp verb command build []
2868 error gyp verb build type Release
2868 error gyp verb architecture arm64
2868 error gyp verb node dev dir /Users/scott/.node-gyp/16.10.0
2868 error gyp verb `which` succeeded for `make` /usr/bin/make
2868 error gyp info spawn make
2868 error gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
2868 error 2 warnings generated.
2868 error In file included from ../src/libsass/src/ast_fwd_decl.cpp:1:
2868 error ../src/libsass/src/ast.hpp:1614:25: warning: loop variable 'numerator' creates a copy from type 'const std::__1::basic_string<char>' [-Wrange-loop-construct]
2868 error for (const auto numerator : numerators)
2868 error ^
2868 error ../src/libsass/src/ast.hpp:1614:14: note: use reference type 'const std::__1::basic_string<char> &' to prevent copying
2868 error for (const auto numerator : numerators)
2868 error ^~~~~~~~~~~~~~~~~~~~~~
2868 error &
2868 error ../src/libsass/src/ast.hpp:1616:25: warning: loop variable 'denominator' creates a copy from type 'const std::__1::basic_string<char>' [-Wrange-loop-construct]
2868 error for (const auto denominator : denominators)
2868 error ^
2868 error ../src/libsass/src/ast.hpp:1616:14: note: use reference type 'const std::__1::basic_string<char> &' to prevent copying
2868 error for (const auto denominator : denominators)
2868 error ^~~~~~~~~~~~~~~~~~~~~~~~
2868 error remove_cv
2868 error /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/type_traits:776:50: note: 'remove_cv' declared here
2868 error template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
2868 error ^
2868 error 1 error generated.
2868 error make: *** [Release/obj.target/binding/src/binding.o] Error 1
2868 error gyp ERR! build error
2868 error gyp ERR! stack Error: `make` failed with exit code: 2
2868 error gyp ERR! stack at ChildProcess.onExit (/*my path*/node_modules/node-gyp/lib/build.js:262:23)
2868 error gyp ERR! stack at ChildProcess.emit (node:events:390:28)
2868 error gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
2868 error gyp ERR! System Darwin 20.6.0
2868 error gyp ERR! command "/opt/homebrew/Cellar/node/16.10.0/bin/node" "/*my path*/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
2868 error gyp ERR! cwd /*my path*/node_modules/node-sass
2868 error gyp ERR! node -v v16.10.0
2868 error gyp ERR! node-gyp -v v3.8.0
2868 error gyp ERR! not ok
2868 error Build failed with error code: 1
2869 verbose exit 1
【问题讨论】:
你可以试试npm cache clean --force
。这解决了我的问题
也可以试试npm rebuild node-sass
@KarmaBlackshaw 没有运气,不幸的是。
有 package-lock.json 吗?你能试着把它去掉吗?
【参考方案1】:
确保“devDependencies”(或“dependencies”)中的“sass-loader”不是旧版本。对我来说,我必须卸载“sass-loader”(旧版本),然后安装“node-sass”,最后安装“sass-loader”(不强制任何版本)。
【讨论】:
【参考方案2】:如果您使用的是 Node 16,请将 node-sass
更改为 >= 6.0.1 版本,然后通过 npm i
重新安装依赖项可能会解决您的问题。请参阅跟踪问题https://github.com/sass/node-sass/issues/3077。
如果失败,您可能需要:
rm -rf node_modules package-lock.json
npm cache clean --force
npm i
【讨论】:
谢谢!!这是唯一适用于我的 M1 机器的解决方案。以上是关于运行 npm install 时 node-sass 出错的主要内容,如果未能解决你的问题,请参考以下文章
运行 npm install cordova 时 npm install 不起作用
当我运行`npm install`时,它返回`ERR!代码 EINTEGRITY` (npm 5.3.0)