Skip to content

Instantly share code, notes, and snippets.

@jackyu
Last active May 8, 2021 09:33
Show Gist options
  • Save jackyu/6ced0a1782f35c6b7a2250a89d19d171 to your computer and use it in GitHub Desktop.
Save jackyu/6ced0a1782f35c6b7a2250a89d19d171 to your computer and use it in GitHub Desktop.
[筆記][錯誤解決] node-sass: Command failed 錯誤

node-sass: Command failed

最近嘗試執行公司的專案時,因專案需要的 node 版本是鎖定在 8.11.4,在執行 yarn install 的過程時,發生以下錯誤:

warning Error running install script for optional dependency: "/Users/user/Documents/project/fe-desktop/node_modules/fsevents: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /Users/user/Documents/project/fe-desktop/node_modules/fsevents
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.6.32
node-pre-gyp info using node@8.11.4 | darwin | x64
node-pre-gyp info check checked for \"/Users/user/Documents/project/fe-desktop/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node\" (not found)
node-pre-gyp http GET https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v57-darwin-x64.tar.gz
node-pre-gyp http 404 https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v57-darwin-x64.tar.gz
node-pre-gyp ERR! Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v57-darwin-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for fsevents@1.0.17 and node@8.11.4 (node-v57 ABI) (falling back to source compile with node-gyp)
node-pre-gyp http 404 status code downloading tarball https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.0.17/fse-v1.0.17-node-v57-darwin-x64.tar.gz
gyp info it worked if it ends with ok
gyp info using node-gyp@3.5.0
gyp info using node@8.11.4 | darwin | x64
gyp info ok
gyp info it worked if it ends with ok
gyp info using node-gyp@3.5.0
gyp info using node@8.11.4 | darwin | x64
gyp info spawn /usr/bin/python
gyp info spawn args [ '/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/user/Documents/project/fe-desktop/node_modules/fsevents/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/user/.node-gyp/8.11.4/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/user/.node-gyp/8.11.4',
gyp info spawn args   '-Dnode_gyp_dir=/Users/user/Documents/project/fe-desktop/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/user/Documents/project/fe-desktop/node_modules/fsevents',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Traceback (most recent call last):
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/gyp_main.py\", line 16, in <module>
    sys.exit(gyp.script_main())
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 545, in script_main
    return main(sys.argv[1:])
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 538, in main
    return gyp_main(args)
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/__init__.py\", line 523, in gyp_main
    generator.GenerateOutput(flat_list, targets, data, params)
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py\", line 2170, in GenerateOutput
    part_of_all=qualified_target in needed_targets)
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py\", line 817, in Write
    mac_bundle_deps, extra_outputs, part_of_all)
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py\", line 1453, in WriteTarget
    lambda p: Sourceify(self.Absolutify(p)))
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py\", line 809, in GetLdflags
    archs = self.GetActiveArchs(self.configname)
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py\", line 420, in GetActiveArchs
    xcode_archs_default = GetXcodeArchsDefault()
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py\", line 118, in GetXcodeArchsDefault
    xcode_version, _ = XcodeVersion()
  File \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py\", line 1265, in XcodeVersion
    version = re.match(r'(\\d\\.\\d\\.?\\d*)', version).groups()[0]
AttributeError: 'NoneType' object has no attribute 'groups'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/lib/configure.js:308:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 20.3.0
gyp ERR! command \"/Users/user/.nvm/versions/node/v8.11.4/bin/node\" \"/Users/user/Documents/project/fe-desktop/node_modules/node-gyp/bin/node-gyp.js\" \"configure\" \"--fallback-to-build\" \"--module=/Users/user/Documents/project/fe-desktop/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node\" \"--module_name=fse\" \"--module_path=/Users/user/Documents/project/fe-desktop/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64\" \"--python=/usr/bin/python\"
gyp ERR! cwd /Users/user/Documents/project/fe-desktop/node_modules/fsevents
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/Users/user/.nvm/versions/node/v8.11.4/bin/node /Users/user/Documents/project/fe-desktop/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/Users/user/Documents/project/fe-desktop/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node --module_name=fse --module_path=/Users/user/Documents/project/fe-desktop/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64 --python=/usr/bin/python' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/user/Documents/project/fe-desktop/node_modules/fsevents/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:126:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:925:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
node-pre-gyp ERR! System Darwin 20.3.0
node-pre-gyp ERR! command \"/Users/user/.nvm/versions/node/v8.11.4/bin/node\" \"/Users/user/Documents/project/fe-desktop/node_modules/fsevents/node_modules/.bin/node-pre-gyp\" \"install\" \"--fallback-to-build\"
node-pre-gyp ERR! cwd /Users/user/Documents/project/fe-desktop/node_modules/fsevents
node-pre-gyp ERR! node -v v8.11.4
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok
Failed to execute '/Users/user/.nvm/versions/node/v8.11.4/bin/node /Users/user/Documents/project/fe-desktop/node_modules/node-gyp/bi[1/7] ⡀ fsevents
[-/7] ⡀ waiting...
[-/7] ⡀ waiting...
[-/7] ⡀ waiting...
error /Users/user/Documents/project/fe-desktop/node_modules/node-sass: Command failed.

起初一直以為是 XCode 沒裝造成,還特地裝了 XCode 和 Command line tools,但依舊無效 而 fs-event 是某個套件中依賴使用,也無法透過 npm i fs-event@latest 來解決 最後這招,可以成功解決

package.json 中加入以下程式碼,再執行 yarn install / npm install 即可

"resolutions": {
	"**/**/node-gyp": "5.0.0"
}

這個做法其實是將套件中依賴的 node-gyp 套件,一律採用 5.0.0 版本

過往在開發時,使用第三方套件,如果開發者不再維護或更新對應套件,而這套件版本剛好也有問題,我們需要強制將套件升級到特定版本時,就可以使用 resolutions 設定,就能覆蓋版本定義

參考資料:

Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.4/fse-v1.2.4-node-v67-darwin-x64.tar.gz package.json中的resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment