我正在尝试将 Svelte js 应用程序放入 Docker 容器中,但是日志中出现了关于 esbuild 在不同平台上的错误。我正在使用 M1 Mac,我尝试安装 esbuild-wasm
,如日志所建议,并在 Docker 文件中尝试了 npm i esbuild-linux-arm64
作为步骤,并尝试了 RUN npm install yarn
,因为日志建议使用内置工具处理平台,但它没有起作用。
我的 Docker 文件:
FROM node:16.10.0
WORKDIR /my-website
COPY package.json .
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
错误在于
You installed esbuild on another platform than the one you're currently using.
This won't work because esbuild is written with native code and needs to
install a platform-specific binary executable.
Specifically the "esbuild-darwin-arm64" package is present but this platform
needs the "esbuild-linux-arm64" package instead. People often get into this
situation by installing esbuild on Windows or macOS and copying "node_modules"
into a Docker image that runs Linux, or by copying "node_modules" between
Windows and WSL environments.
esbuild
的是什么(您是否在 Dockerfile 中缺少RUN npm run build
行)?您是否在.dockerignore
文件中排除了主机的node_modules
目录?您是在构建镜像或运行容器时遇到此错误,如果正在运行,则是否使用volumes:
替换了镜像内容? - David Mazeversion: '3.8' services: rad-website: build: context: . dockerfile: Dockerfile ports: - "3000:3000" volumes: - .:/my-website - /my-website/node_modules/
- Yusuf