【注意】最后更新于 December 3, 2021,文中内容可能已过时,请谨慎使用。
最近尝试将前端项目编译成docker方便管理,但是遇到当项目里依赖于node-sass报如下错误
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
gyp verb could not find "python". checking python launcher
gyp verb could not find "python". guessing location
gyp verb ensuring that file exists: C:\Python27\python.exe
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (E:\code\mydyh\vue-admin-pro-master\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack at PythonFinder.<anonymous> (E:\code\mydyh\vue-admin-pro-master\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack at callback (E:\code\mydyh\vue-admin-pro-master\node_modules\graceful-fs\polyfills.js:289:20)
gyp ERR! stack at FSReqCallback.oncomplete (fs.js:183:21)
gyp ERR! System Windows_NT 10.0.19042
gyp ERR! command "D:\\ProgramFiles\\nodejs\\node.exe" "E:\\code\\mydyh\\vue-admin-pro-master\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd E:\code\mydyh\vue-admin-pro-master\node_modules\node-sass
gyp ERR! node -v v14.16.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.12.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.12.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Roaming\npm-cache\_logs\2021-05-13T10_26_43_202Z-debug.log
|
问题原因是,node-sass编译依赖于python
解决方案
1
2
3
4
|
#安装依赖
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add python3 && npm config set registry "https://registry.npm.taobao.org/" \
&& npm install --python=python3 \
&&npm install
|