Project scenario:
A vue project using node-sass, pulled from the remote code base to the local
Problem Description
Failed to install project dependencies normally
error D:\My prgram\demo-proj\node_modules\node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: D:\My prgram\demo-proj\node_modules\node-sass
Output:
Building: D:\Program Files\nodejs\node.exe D:\My prgram\demo-proj\node_modules\node-gyp\bin\node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli 'D:\\Program Files\\nodejs\\node.exe',
gyp verb cli 'D:\\My prgram\\demo-proj\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli 'rebuild',
gyp verb cli '--verbose',
gyp verb cli '--libsass_ext=',
gyp verb cli '--libsass_cflags=',
gyp verb cli '--libsass_ldflags=',
gyp verb cli '--libsass_library='
gyp verb cli ]
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed at getNotFoundError (D:\My prgram\demo-proj\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (D:\My prgram\demo-proj\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (D:\My prgram\demo-proj\node_modules\which\which.js:80:29)
gyp verb `which` failed at D:\My prgram\demo-proj\node_modules\which\which.js:89:16
gyp verb `which` failed at D:\My prgram\demo-proj\node_modules\isexe\index.js:42:5
gyp verb `which` failed at D:\My prgram\demo-proj\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:192:21)
gyp verb `which` failed python2 Error: not found: python2
gyp verb `which` failed at getNotFoundError (D:\My prgram\demo-proj\node_modules\which\which.js:13:12)
gyp verb `which` failed at F (D:\My prgram\demo-proj\node_modules\which\which.js:68:19)
gyp verb `which` failed at E (D:\My prgram\demo-proj\node_modules\which\which.js:80:29)
gyp verb `which` failed at D:\My prgram\demo-proj\node_modules\which\which.js:89:16
gyp verb `which` failed at D:\My prgram\demo-proj\node_modules\isexe\index.js:42:5
gyp verb `which` failed at D:\My prgram\demo-proj\node_modules\isexe\windows.js:36:5
gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:192:21) {
gyp verb `which` failed code: 'ENOENT'
gyp verb `which` failed }
gyp verb `which` succeeded python D:\My prgram\Python\Python3.6.5\python.EXE
gyp ERR! configure error
gyp ERR! stack Error: Command failed: D:\My prgram\Python\Python3.6.5\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "<string>", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (node:child_process:309:12)
gyp ERR! stack at ChildProcess.emit (node:events:376:20)
gyp ERR! stack at maybeClose (node:internal/child_process:1055:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "D:\\Program Files\\nodejs\\node.exe" "D:\\My prgram\\demo-proj\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd D:\My prgram\demo-proj\node_modules\node-sass
gyp ERR! node -v v15.3.0
Related links
node-sass Git / Gitee
dart-sass
node-sass installation failure solution
Cause Analysis:
> Wall
The first guess may be that some packages are outside the wall, which was quickly ruled out
> npm/yarn cache
I have encountered this problem on other devices before. I used the solution in this article to solve the problem, but I didn’t go into the solution of
node-sass installation failure.
But in fact, this is not the case for most of them. the reason for the situation
1. Compatibility of node versions
I remembered that my colleague also encountered this problem after pulling the code. At that time, my node version was v14.16.0
15+. After reinstalling node@14, you can install the project dependencies
Obviously, this means that node-sass does not support node@15+
node-sass also states this in the git repository
“Warning: LibSass and Node Sass are deprecated. While they will continue to receive maintenance releases indefinitely, there are no plans to add additional features or compatibility with any new CSS or Sass features. Projects that still use it should move onto Dart Sass.”
As you can see, the official recommendation is to use Dart Sass, but if you don’t want (dare) to move node-sass, you can continue to look down
NodeJS | Supported node-sass version | Node Module |
---|---|---|
Node 17 | 7.0+ | 102 |
Node 16 | 6.0+ | 93 |
Node 15 | 5.0+, <7.0 | 88 |
Node 14 | 4.14+ | 83 |
Node 13 | 4.13+, <5.0 | 79 |
Node 12 | 4.12+ | 72 |
Node 11 | 4.10+, <5.0 | 67 |
Node 10 | 4.9+, <6.0 | 64 |
Node 8 | 4.5.3+, <5.0 | 57 |
Node <8 | <5.0 | <57 |
A more detailed way to view version compatibility is to view the release list of node-sass
Example:
First get the binding.node applicable to your node version
C:\Users\YMZhao>node -p "[process.platform, process.arch, process.versions.modules].join('-')"
win32-x64-88
The following is a list of [email protected], no win32-x64-88_binding.node
, it is not compatible with your node version
Check out that [email protected] is compatible with node@15
After updating node-sass to v5.0.0, new problems appeared:
ERROR Failed to compile with 1 error
error in ./src/styles/index.scss
Syntax Error: Error: Node Sass version 5.0.0 is incompatible with ^4.0.0.
The reason is "sass-loader": "^8.0.2"
incompatibility with ! !
Error: "node-sass" version 5.0.0 is incompatible with ^4.0.0
Some netizens tried, [email protected] is compatible with [email protected]
2. Replace node-sass with dart-sass
As mentioned above, node-sass officials recommend replacing it with dart-sass
“If you’re a user of Node Sass, migrating to Dart Sass is straightforward: just replace node-sass
in your package.json
file with sass
. Both packages expose the same JavaScript API.”
Use npm/yarn to uninstall node-sass and install sass
yarn remove node-sass
yarn add sass -D
solution:
According to the analysis in the previous section, there are three solutions:
1. Use dart-sass
to replace node-sass
2. Install node@14
3. Node@15, [email protected], [email protected]
The latter two need to follow the examples in the previous section to ensure that node-sass is compatible with your node version