Docker:Node Sass找不到适用于当前环境的绑定:Linux/musl 64位Node.js 10.x



我在Windows 10上使用带有实时重新加载的Docker,通过React前端、Node.js后端和Nginx服务器进行本地开发。我可以启动这三项服务并检测更改,但无论我做什么,客户端每次都无法编译

Failed to compile.
client_1  | ./src/main.scss (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-5-1!./node_modules/postcss-loader/src??postcss!./node_modules/resolve-url-loader??ref--6-oneOf-5-3!./node_modules/sass-loader/dist/cjs.js??ref--6-oneOf-5-4!./src/main.scss)
client_1  | Error: Missing binding /client/node_modules/node-sass/vendor/linux_musl-x64-64/binding.node
client_1  | Node Sass could not find a binding for your current environment: Linux/musl 64-bit with Node.js 10.x
client_1  |
client_1  | Found bindings for the following environments:
client_1  |   - Windows 64-bit with Node.js 12.x
client_1  |
client_1  | This usually happens because your environment has changed since running `npm install`.
client_1  | Run `npm rebuild node-sass` to download the binding for your current environment.

我首先在本地安装包,然后创建容器并使用dockercompose构建图像。

client/Dockerfile.dev

FROM node:lts
WORKDIR /client
EXPOSE 3000
CMD ["npm", "start"]

docker compose.dev.yml(为了简洁起见,去掉了其他服务(

version: "3"
services:
client:
build:
context: client
dockerfile: Dockerfile.dev
image: myapp-client
environment:
- NODE_ENV=development
volumes:
- ./client:/
- ./client:/node_modules
ports:
- "3000:3000"
tty: true

我已经尝试过这些Node.js图像,但没有成功:

node:10
node:latest
node:lts
node:10.16.3
node:8.1.0-alpine

我读过关于在RUN npm install之后在Dockerfile中使用RUN npm rebuild node-sass的文章,但这只适用于生产,因为对于本地开发,我将从package.json中的脚本安装我的包

这就是对我的作用

sudo ln -s /home/user/.nvm/versions/node/v12.18.2/bin/node /usr/bin/node

我今天也遇到过同样的情况。我在我的React客户端中使用sass,这需要node-sass。下一步是对客户端进行码头化,这就是我偶然发现这个问题的时候。我的Dockerfile和docker-compose.yml与问题中提供的非常相似,除了docker-compose.yml中的volumes,如下所示-

- ./client:/app
- /app/node_modules

Dockerfile中的我的WORKDIR是/app

最新更新