前提・実現したいこと
docker
rails6 + mysql + nginx + puma
の構成でアプリケーションを開発しています
rails6 + mysql
の開発環境では問題なく動いたのですがいざ本番環境を立ち上げると各コンテナは起動するものの、500 internetservererrorが返ってきてしまいます。
nginx側にエラーメッセージは出ておらず、Rails側のproduction.logを見ると以下のエラーが発生していました。
発生している問題・エラーメッセージ
I, [2020-11-30T06:37:40.948194 #1] INFO -- : [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] Started GET "/" for 127.0.0.1 at 2020-11-30 06:37:40 +0000 I, [2020-11-30T06:37:40.948876 #1] INFO -- : [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] Processing by StaticPagesController#home as HTML I, [2020-11-30T06:37:40.949699 #1] INFO -- : [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] Rendering static_pages/home.html.erb within layouts/application I, [2020-11-30T06:37:40.950476 #1] INFO -- : [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] Rendered static_pages/home.html.erb within layouts/application (Duration: 0.6ms | Allocations: 210) I, [2020-11-30T06:37:40.951492 #1] INFO -- : [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] Completed 500 Internal Server Error in 2ms (Allocations: 804) F, [2020-11-30T06:37:40.962658 #1] FATAL -- : [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] ActionView::Template::Error (Webpacker can't find application in /FSC_app/public/packs/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: { "application.js": "/packs/js/application-7134d39647120a7c1d01.js", "application.js.map": "/packs/js/application-7134d39647120a7c1d01.js.map", "entrypoints": { "application": { "js": [ "/packs/js/application-7134d39647120a7c1d01.js" ], "js.map": [ "/packs/js/application-7134d39647120a7c1d01.js.map" ] }, "server_rendering": { "js": [ "/packs/js/server_rendering-e8d899150a6b916d4bbc.js" ], "js.map": [ "/packs/js/server_rendering-e8d899150a6b916d4bbc.js.map" ] } }, "server_rendering.js": "/packs/js/server_rendering-e8d899150a6b916d4bbc.js", "server_rendering.js.map": "/packs/js/server_rendering-e8d899150a6b916d4bbc.js.map" } ): [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 6: <title>FSCmanager</title> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 7: <%= csrf_meta_tags %> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 8: <%= csp_meta_tag %> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 9: <%= stylesheet_pack_tag 'application'%> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 10: <%= javascript_pack_tag 'application' %> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 11: <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] 12: <link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" /> [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] [3b9b75a6-449d-4cca-93d0-224a85f9ed9e] app/views/layouts/application.html.erb:9
webpackコンパイル自体は特にエラー文が出ることもなく実行できます(文字数の関係でログを載せられませんでした)
webpackに明るくないため原因が特定できないのですがRailsで使用しているReact(react-railsというgemで導入),Bootstrap4(こちらはCDNでライブラリを読み込んでいる)が原因かと推測しております。
問題がありそうなファイルのコードを記しますので皆さんの知恵をお貸しください。
application.html.erb
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>FSCmanager</title> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_pack_tag 'application'%> <%= javascript_pack_tag 'application' %> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <link href="/assets/application.css" media="all" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> <meta name="viewport" content="width=device-width, initial-scale=1" /> </head> <body> <%= render 'layouts/header' %> <%= render 'layouts/flashes' %> <p></p> <div class="container"> <%= yield %> </div> </body> </html>
applicatin.js
import "stylesheets/application"; require("@rails/ujs").start() require("@rails/activestorage").start() require("channels") require("jquery") var componentRequireContext = require.context("components", true); var ReactRailsUJS = require("react_ujs"); ReactRailsUJS.useContext(componentRequireContext);
babel.config.js
module.exports = function(api) { var validEnv = ['development', 'test', 'production'] var currentEnv = api.env() var isDevelopmentEnv = api.env('development') var isProductionEnv = api.env('production') var isTestEnv = api.env('test') if (!validEnv.includes(currentEnv)) { throw new Error( 'Please specify a valid `NODE_ENV` or ' + '`BABEL_ENV` environment variables. Valid values are "development", ' + '"test", and "production". Instead, received: ' + JSON.stringify(currentEnv) + '.' ) } return { presets: [ isTestEnv && [ "@babel/preset-env", { targets: { node: "current", }, }, ], (isProductionEnv || isDevelopmentEnv) && [ "@babel/preset-env", { forceAllTransforms: true, useBuiltIns: "entry", corejs: 3, modules: false, exclude: ["transform-typeof-symbol"], }, ], ].filter(Boolean), plugins: [ "babel-plugin-macros", "@babel/plugin-syntax-dynamic-import", isTestEnv && "babel-plugin-dynamic-import-node", "@babel/plugin-transform-destructuring", [ "@babel/plugin-proposal-class-properties", { loose: true, }, ], [ "@babel/plugin-transform-react-jsx", { loose: true, }, ], [ "@babel/plugin-proposal-object-rest-spread", { useBuiltIns: true, }, ], [ "@babel/plugin-transform-runtime", { helpers: false, regenerator: true, corejs: false, }, ], [ "@babel/plugin-transform-regenerator", { async: false, }, ], ].filter(Boolean), }; }
webpacker.yml
default: &default source_path: app/javascript source_entry_path: packs public_root_path: public public_output_path: packs cache_path: tmp/cache/webpacker check_yarn_integrity: true webpack_compile_output: true # Additional paths webpack should lookup modules # ['app/assets', 'engine/foo/app/assets'] resolved_paths: ['app/assets'] # Reload manifest.json on all requests so we reload latest compiled packs cache_manifest: true # Extract and emit a css file extract_css: true static_assets_extensions: - .jpg - .jpeg - .png - .gif - .tiff - .ico - .svg - .eot - .otf - .ttf - .woff - .woff2 extensions: - .mjs - .js - .jsx - .sass - .scss - .css - .module.sass - .module.scss - .module.css - .png - .svg - .gif - .jpeg - .jpg development: <<: *default compile: true # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules check_yarn_integrity: true # Reference: https://webpack.js.org/configuration/dev-server/ dev_server: https: false host: localhost port: 3035 public: localhost:3035 hmr: false # Inline should be set to true if using HMR inline: true overlay: true compress: true disable_host_check: true use_local_ip: false quiet: false pretty: false headers: 'Access-Control-Allow-Origin': '*' watch_options: ignored: '**/node_modules/**' test: <<: *default compile: true # Compile test packs to a separate directory public_output_path: packs-test production: <<: *default # Production depends on precompilation of packs prior to booting for performance. compile: true # Extract and emit a css file extract_css: true # Cache manifest.json for performance cache_manifest: true
補足情報(FW/ツールのバージョンなど)
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
Rails 6.0.3.4
webpack@4.44.1
react@17.0.1
あなたの回答
tips
プレビュー