如何在 MacOSX M1 上安装 node-sass?

Ant*_*rka 4 node.js npm node-sass

当尝试在我的 M1 MacBook 上执行操作时,我遇到了 node-sass 错误yarn

我有这个错误:

error /Users/antoinekurka/Documents/Freelance/Projets/NL/NextLevel/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: /Users/antoinekurka/Documents/Freelance/Projets/NL/NextLevel/node_modules/node-sass
Output:
Building: /opt/homebrew/Cellar/node/17.8.0/bin/node /Users/antoinekurka/Documents/Freelance/Projets/NL/NextLevel/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   '/opt/homebrew/Cellar/node/17.8.0/bin/node',
gyp verb cli   '/Users/antoinekurka/Documents/Freelance/Projets/NL/NextLevel/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 node-gyp@3.8.0
gyp info using node@17.8.0 | darwin | arm64
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 "/usr/bin/python3" in the PATH
gyp verb `which` succeeded /usr/bin/python3 /usr/bin/python3
gyp ERR! configure error
gyp ERR! stack Error: Command failed: /usr/bin/python3 -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:398:12)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1090:16)
gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:449:11)
gyp ERR! stack     at Socket.emit (node:events:527:28)
gyp ERR! stack     at Pipe.<anonymous> (node:net:709:12)
gyp ERR! System Darwin 21.4.0
gyp ERR! command "/opt/homebrew/Cellar/node/17.8.0/bin/node" "/Users/antoinekurka/Documents/Freelance/Projets/NL/NextLevel/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /Users/antoinekurka/Documents/Freelance/Projets/NL/NextLevel/node_modules/node-sass
gyp ERR! node -v v17.8.0
Run Code Online (Sandbox Code Playgroud)

我也尝试在节点 12 和 14 上执行此操作。

在 package.json 中我有这个:

"node-sass": "^4.11.0",
"sass-loader": "^9.0.3",
Run Code Online (Sandbox Code Playgroud)

我尝试了不同版本的 node-sass 但没有任何效果。

每次我尝试时,我都会删除/node_modules、package-lock.json和yarn.lock

有人知道如何解决这个问题吗?

谢谢

小智 6

node-sass 已被弃用,许多人在使用 ARM 架构安装它时遇到了问题。请在此处查看更多详细信息:https://sass-lang.com/blog/libsass-is-deprecated。如果可以的话,请使用 sass 代替。 yarn add -D sass


Nic*_*aeS 5

我通过使用解决了这个问题python2.7。使用pyenv,您可以执行以下操作:

pyenv install 2.7
pyenv local 2.7
Run Code Online (Sandbox Code Playgroud)