M1芯片 Macbook Air 本地 Docker 前端构建镜像报错(node-sass)

本文介绍了在M1芯片的Macbook Air上使用Docker构建前端镜像时遇到的node-sass错误,详细记录了从升级Python到更新Node.js的尝试过程,最终发现由于不支持arm架构导致的问题。解决方案是将node-sass替换为sass,并在Dockerfile中设置环境变量进行安装。

M1芯片 Macbook Air 本地 Docker 前端构建镜像报错

gyp verb find Python Python is not set from command line or npm configuration
在这里插入图片描述
在这里插入图片描述

一开始本地是默认python 2.7,查说让更新到 3版本,我更新到了 3.10。然而仍然失败。

下载安装,然后配置

vim ~/.bash_profile

添加如下内容:
alias python=“/usr/local/bin/python3.10”

然而并不好用

又查发现要更新node 版本到 15,当前是 14.8.1遂更新node 到 15.4。
仍然失败.

放弃!

经不懈努力,发现不支持arm
https://github.com/sass/node-sass/releases/download/v4.14.1/linux-arm64-83_binding.node
这才是错误的根源。

好了把包里的 node-sass 改成 sass 就行了

#11 91.68 npm ERR! gyp info it worked if it ends with ok
#11 91.68 npm ERR! gyp info using node-gyp@8.4.1
#11 91.68 npm ERR! gyp info using node@16.14.2 | linux | arm64
#11 91.68 npm ERR! gyp ERR! find Python 
#11 91.68 npm ERR! gyp ERR! find Python Python is not set from command line or npm configuration
#11 91.68 npm ERR! gyp ERR! find Python Python is not set from environment variable PYTHON
#11 91.68 npm ERR! gyp ERR! find Python checking if "python3" can be used
#11 91.68 npm ERR! gyp ERR! find Python - "python3" is not in PATH or produced an error
#11 91.68 npm ERR! gyp ERR! find Python checking if "python" can be used
#11 91.68 npm ERR! gyp ERR! find Python - "python" is not in PATH or produced an error
#11 91.68 npm ERR! gyp ERR! find Python 
#11 91.68 npm ERR! gyp ERR! find Python **********************************************************
#11 91.68 npm ERR! gyp ERR! find Python You need to install the latest version of Python.
#11 91.68 npm ERR! gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
#11 91.68 npm ERR! gyp ERR! find Python you can try one of the following options:
#11 91.68 npm ERR! gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
#11 91.68 npm ERR! gyp ERR! find Python   (accepted by both node-gyp and npm)
#11 91.68 npm ERR! gyp ERR! find Python - Set the environment variable PYTHON
#11 91.68 npm ERR! gyp ERR! find Python - Set the npm configuration variable python:
#11 91.68 npm ERR! gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
#11 91.68 npm ERR! gyp ERR! find Python For more information consult the documentation at:
#11 91.68 npm ERR! gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
#11 91.68 npm ERR! gyp ERR! find Python **********************************************************
#11 91.68 npm ERR! gyp ERR! find Python 
#11 91.68 npm ERR! gyp ERR! configure error 
#11 91.68 npm ERR! gyp ERR! stack Error: Could not find any Python installation to use
#11 91.68 npm ERR! gyp ERR! stack     at PythonFinder.fail (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:330:47)
#11 91.68 npm ERR! gyp ERR! stack     at PythonFinder.runChecks (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:159:21)
#11 91.68 npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:202:16)
#11 91.68 npm ERR! gyp ERR! stack     at PythonFinder.execFileCallback (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/find-python.js:294:16)
#11 91.68 npm ERR! gyp ERR! stack     at exithandler (node:child_process:406:5)
#11 91.68 npm ERR! gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:418:5)
#11 91.68 npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:526:28)
#11 91.68 npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
#11 91.68 npm ERR! gyp ERR! stack     at onErrorNT (node:internal/child_process:478:16)
#11 91.68 npm ERR! gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
#11 91.68 npm ERR! gyp ERR! System Linux 5.10.76-linuxkit
#11 91.68 npm ERR! gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
#11 91.68 npm ERR! gyp ERR! cwd /app/node_modules/deasync
#11 91.68 npm ERR! gyp ERR! node -v v16.14.2
#11 91.68 npm ERR! gyp ERR! node-gyp -v v8.4.1
#11 91.68 npm ERR! gyp ERR! not ok 
#11 91.68 npm ERR! Build failed
#11 91.68 
#11 91.68 npm ERR! A complete log of this run can be found in:
#11 91.68 npm ERR!     /root/.npm/_logs/2022-04-10T03_34_23_844Z-debug-0.log
------
executor failed running [/bin/sh -c npm install     && npm run build:${MODE}]: exit code: 1

在dockerfile npm install 前添加环境变量安装就可以了

RUN apk add g++ make python
RUN npm install \
    && npm run build:${MODE}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值