質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 7

Ruby on Rails 7は、2021年12月に正式リリースされました。Ruby on Railsのバージョン7であり、フロントエンド開発環境を大幅に刷新。Node.jsを用いない構成がデフォルトになっています。

Q&A

解決済

2回答

2474閲覧

【Rails7】bin/devを実行した時にesbuildが動かない

koki_226

総合スコア1

Ruby on Rails 7

Ruby on Rails 7は、2021年12月に正式リリースされました。Ruby on Railsのバージョン7であり、フロントエンド開発環境を大幅に刷新。Node.jsを用いない構成がデフォルトになっています。

0グッド

0クリップ

投稿2023/01/14 05:55

前提

Rails 7.0.4
ruby 3.2.0
node 18.13.0

Ruby on Rails初学者です。
rails sでサーバーを立ち上げることはできるのですが、bin/devを実行した際にerrorが出てしまいます。
esbuildが動いていないように思うのですが、自分では解決できなかったため質問させていただきます。

実現したいこと

  • bin/dev でサーバーを立ち上げてbuildする

発生している問題・エラーメッセージ

bin/dev 14:26:22 web.1 | started with pid 43688 14:26:22 js.1 | started with pid 43689 14:26:23 js.1 | yarn run v1.22.19 14:26:23 js.1 | $ node esbuild.config.js --watch 14:26:26 js.1 | /Users/seoakirahajime/Documents/Cajon/Hairbook/node_modules/esbuild/lib/main.js:1841 14:26:26 js.1 | throw new Error(` 14:26:26 js.1 | ^ 14:26:26 js.1 | 14:26:26 js.1 | Error: 14:26:26 js.1 | You installed esbuild for another platform than the one you're currently using. 14:26:26 js.1 | This won't work because esbuild is written with native code and needs to 14:26:26 js.1 | install a platform-specific binary executable. 14:26:26 js.1 | 14:26:26 js.1 | Specifically the "@esbuild/darwin-arm64" package is present but this platform 14:26:26 js.1 | needs the "@esbuild/darwin-x64" package instead. People often get into this 14:26:26 js.1 | situation by installing esbuild with npm running inside of Rosetta 2 and then 14:26:26 js.1 | trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta 14:26:26 js.1 | 2 is Apple's on-the-fly x86_64-to-arm64 translation service). 14:26:26 js.1 | 14:26:26 js.1 | If you are installing with npm, you can try ensuring that both npm and node are 14:26:26 js.1 | not running under Rosetta 2 and then reinstalling esbuild. This likely involves 14:26:26 js.1 | changing how you installed npm and/or node. For example, installing node with 14:26:26 js.1 | the universal installer here should work: https://nodejs.org/en/download/. Or 14:26:26 js.1 | you could consider using yarn instead of npm which has built-in support for 14:26:26 js.1 | installing a package on multiple platforms simultaneously. 14:26:26 js.1 | 14:26:26 js.1 | If you are installing with yarn, you can try listing both "arm64" and "x64" 14:26:26 js.1 | in your ".yarnrc.yml" file using the "supportedArchitectures" feature: 14:26:26 js.1 | https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures 14:26:26 js.1 | Keep in mind that this means multiple copies of esbuild will be present. 14:26:26 js.1 | 14:26:26 js.1 | Another alternative is to use the "esbuild-wasm" package instead, which works 14:26:26 js.1 | the same way on all platforms. But it comes with a heavy performance cost and 14:26:26 js.1 | can sometimes be 10x slower than the "esbuild" package, so you may also not 14:26:26 js.1 | want to do that. 14:26:26 js.1 | 14:26:26 js.1 | at generateBinPath (/Users/seoakirahajime/Documents/Cajon/Hairbook/node_modules/esbuild/lib/main.js:1841:17) 14:26:26 js.1 | at esbuildCommandAndArgs (/Users/seoakirahajime/Documents/Cajon/Hairbook/node_modules/esbuild/lib/main.js:1922:33) 14:26:26 js.1 | at ensureServiceIsRunning (/Users/seoakirahajime/Documents/Cajon/Hairbook/node_modules/esbuild/lib/main.js:2087:25) 14:26:26 js.1 | at Object.build (/Users/seoakirahajime/Documents/Cajon/Hairbook/node_modules/esbuild/lib/main.js:1978:26) 14:26:26 js.1 | at file:///Users/seoakirahajime/Documents/Cajon/Hairbook/esbuild.config.js:22:9 14:26:26 js.1 | at ModuleJob.run (node:internal/modules/esm/module_job:197:25) 14:26:26 js.1 | at async Promise.all (index 0) 14:26:26 js.1 | at async ESMLoader.import (node:internal/modules/esm/loader:337:24) 14:26:26 js.1 | at async loadESM (node:internal/process/esm_loader:88:5) 14:26:26 js.1 | at async handleMainPromise (node:internal/modules/run_main:61:12) 14:26:26 js.1 | error Command failed with exit code 1. 14:26:26 js.1 | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. 14:26:26 js.1 | exited with code 1 14:26:26 system | sending SIGTERM to all processes 14:26:26 web.1 | terminated by SIGTERM

installしたpackageが違うと言われているのですが、よく分からず解決できてないです。
環境構築についての知識がほとんどないため、教えていただけたら助かります。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

VScodeターミナルでRosseta2が有効になっていなかったことが原因だった。

macのターミナルではRosseta2を有効にしていたにもかかわらず、VScodeのターミナルではRosseta2が無効になっていた。
Rosseta2の設定はVScodeのアプリを右クリックで設定箇所があるので、Rosseta2を有効にした。
その結果、無事動くようになった。

投稿2023/03/17 08:23

koki_226

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

node_modulesを削除して、パッケージを再インストールすれば解決しました。

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

追記

再度同じエラーが出てしいます。
もう一度パッケージの再インストールをすれば動くようにはなるのですが、再発してしまう原因がよく分からないです。

投稿2023/01/15 12:46

編集2023/01/23 04:16
koki_226

総合スコア1

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問