前提
$rails test
をした際に、Webpacker can't find application
とエラーが吐かれたので
RSpecを実行すると'Webpacker can't find ~'となる時の対処法を参考にWebpacker
を再インストールしコンパイルしようとしました
###実現したいこと
Webpacker
をコンパイルした時、失敗してしまったのでコンパイルできるようにしたいです。
最終的には$rails test
が正常に行われるようにしたいです。
発生している問題・エラーメッセージ
rails test
をした時のエラー
terminal
1$ rails test 2Run options: --seed 60799 3 4# Running: 5 6E 7 8Error: 9StaticPagesControllerTest#test_should_get_home: 10ActionView::Template::Error: Webpacker can't find application in /home/ubuntu/environment/sample_app/public/packs-test/manifest.json. Possible causes: 111. You want to set webpacker.yml value of compile to true for your environment 12 unless you are using the `webpack -w` or the webpack-dev-server. 132. webpack has not yet re-run to reflect updates. 143. You have misconfigured Webpacker's config/webpacker.yml file. 154. Your webpack configuration is not creating a manifest. 16Your manifest contains: 17{ 18} 19 20 app/views/layouts/application.html.erb:9 21 test/controllers/static_pages_controller_test.rb:5:in `block in <class:StaticPagesControllerTest>'
コンパイルが失敗した時のエラー文
$ rm -rf bin/webpack* $ rails webpacker:install 省略 $ RAILS_ENV=test bundle exec rails webpacker:compile Compiling… Compilation failed: [webpack-cli] Failed to load '/home/ubuntu/environment/sample_app/config/webpack/production.js' [webpack-cli] TypeError: Cannot read property 'toWebpackConfig' of undefined at Object.<anonymous> (/home/ubuntu/environment/sample_app/config/webpack/production.js:5:30) at Module._compile (/home/ubuntu/environment/sample_app/node_modules/v8-compile-cache/v8-compile-cache.js:192:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:692:17) at require (/home/ubuntu/environment/sample_app/node_modules/v8-compile-cache/v8-compile-cache.js:159:20) at loadConfig (/home/ubuntu/environment/sample_app/node_modules/webpack-cli/lib/webpack-cli.js:869:31) at Promise.all.options.config.map (/home/ubuntu/environment/sample_app/node_modules/webpack-cli/lib/webpack-cli.js:939:48)
試したこと
webpackのインストールと使い方を参考にwebpack
をインストールし直したが、同様のエラーが吐かれる
$rm -rf bin/webpack* $npm install -D webpack webpack-cli npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + webpack-cli@4.4.0 + webpack@5.19.0 updated 8 packages and audited 668 packages in 141.938s 34 packages are looking for funding run `npm fund` for details found 0 vulnerabilities $ rails test Run options: --seed 33598 # Running: E Error: StaticPagesControllerTest#test_should_get_about: ActionView::Template::Error: Webpacker can't find application in /home/ubuntu/environment/sample_app/public/packs-test/manifest.json. Possible causes: 1. You want to set webpacker.yml value of compile to true for your environment unless you are using the `webpack -w` or the webpack-dev-server. 2. webpack has not yet re-run to reflect updates. 3. You have misconfigured Webpacker's config/webpacker.yml file. 4. Your webpack configuration is not creating a manifest. Your manifest contains: { } app/views/layouts/application.html.erb:9 test/controllers/static_pages_controller_test.rb:15:in `block in <class:StaticPagesControllerTest>'
お手数お掛けしますが回答よろしくお願いします
#修正依頼
Failed to load '/home/ubuntu/environment/sample_app/config/webpack/production.js'」と出ていますが、このファイルは存在しますか?
→存在しています。以下そのコードです。
config/webpack/production.js
process.env.NODE_ENV = process.env.NODE_ENV || 'production' const environment = require('./environment') module.exports = environment.toWebpackConfig()
あなたの回答
tips
プレビュー