LoginSignup
5
0

More than 1 year has passed since last update.

yarn build したときのエラー解決方法(Rails7 アプリで esbuild を使用時)

Posted at

エラー内容

以下のようなエラーが出たときの解決方法を記録しておきます。

docker-compose run --rm app yarn build

Creating ***_app_run ... done
yarn run v1.22.17
$ esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds --public-path=app/assets/builds
/myapp/node_modules/esbuild/bin/esbuild:159
          throw new Error(`
          ^

Error: 
You installed esbuild for 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-x64" package is present but this platform
needs the "@esbuild/linux-x64" 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.

If you are installing with npm, you can try not copying the "node_modules"
directory when you copy the files over, and running "npm ci" or "npm install"
on the destination platform after the copy. Or you could consider using yarn
instead of npm which has built-in support for installing a package on multiple
platforms simultaneously.

If you are installing with yarn, you can try listing both this platform and the
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
Keep in mind that this means multiple copies of esbuild will be present.

Another alternative is to use the "esbuild-wasm" package instead, which works
the same way on all platforms. But it comes with a heavy performance cost and
can sometimes be 10x slower than the "esbuild" package, so you may also not
want to do that.

    at generateBinPath (/myapp/node_modules/esbuild/bin/esbuild:159:17)
    at Object.<anonymous> (/myapp/node_modules/esbuild/bin/esbuild:207:27)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: 1

上記のエラーは、
ビルドに使用される esbuild パッケージのバイナリが互換性のないプラットフォームでインストールされていることを示しています。

解決方法

以下のコマンドを実行して、パッケージを再度インストールします。

以下のコマンドを実行して、実行環境にあるnode_modulesを削除します。

rm -rf node_modules

以下のコマンドを実行して、パッケージを再インストールします。

npm install

yarnを使用している場合は、以下のコマンドを実行します。

yarn install

これで、パッケージが再度インストールされます。

さいごに、以下を再度実行して正常に終了することを確認してください。

docker-compose run --rm app yarn build
5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0