记录前端项目在生成docker镜像时遇到esbuild报错
前端项目在生成docker镜像时遇到esbuild时报错。
项目场景:
前端项目在生成docker镜像时遇到esbuild时报错
问题描述
执行docker build -t mobile:v1 . 命令
出现以下报错
12.71 Specifically the "@esbuild/darwin-arm64" package is present but this platform
12.71 needs the "@esbuild/linux-arm64" package instead. People often get into this
12.71 situation by installing esbuild on Windows or macOS and copying "node_modules"
12.71 into a Docker image that runs Linux, or by copying "node_modules" between
12.71 Windows and WSL environments.
12.71
12.71 If you are installing with npm, you can try not copying the "node_modules"
12.71 directory when you copy the files over, and running "npm ci" or "npm install"
12.71 on the destination platform after the copy. Or you could consider using yarn
12.71 instead of npm which has built-in support for installing a package on multiple
12.71 platforms simultaneously.
12.71
12.71 If you are installing with yarn, you can try listing both this platform and the
12.71 other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
12.71 feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
12.71 Keep in mind that this means multiple copies of esbuild will be present.
12.71
12.71 Another alternative is to use the "esbuild-wasm" package instead, which works
12.71 the same way on all platforms. But it comes with a heavy performance cost and
12.71 can sometimes be 10x slower than the "esbuild" package, so you may also not
12.71 want to do that.
原因分析:
我的电脑是苹果m1芯片的,esbuild是@esbuild/darwin-arm64,在Linux环境下需要@esbuild/linux-arm64。
解决方案:
我使用的是pnpm,在node_modules 下的pnpm文件下找到了esbuild文件
里面放的果然是@esbuild/darwin-arm64。
那就去找esbuild,在GitHub中。
https://github.com/evanw/esbuild
点击入门说明
进入说明
命令终端执行示例:
curl -O https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.7.tgz
注意:
1. @esbuild/darwin-x64要换成报错里需要的esbuild。
2. 0.19.7是版本号,可以在项目的pnpm-lock.yaml文件里查到自己需要的版本号
3. 可以在桌面建一个空文件夹来执行命令,这样生成的.tgz就在这个目录里,不需要找了。
4. 不要直接复制这里的命令,最好去网址里复制esbuild提供的,因为命令是有可能变化的, 会导致下载下来的tgz文件是空的,无法解压。
上面执行完毕后执行下面的解压命令
tar xzf ./darwin-x64-0.19.7.tgz
解压后会得到package文件。
我使用pnpm 所以把这个文件放在了node_modules pnpm文件下esbuild文件里,
package文件需要改名为linux-arm64
再次创建镜像,成功了。
更多推荐
所有评论(0)