I know this question has been asked and answered before, but I haven't been able to get things running with what's already available.
I had a react-rails app running, then decided to move to webpacker. I replaced the react-rails gem with webpacker and followed the installation instructions (I allowed the installs to overwrite any old files).
I then moved my code from the asset/pipeline into app/javascript/components, modified my home#index to use the javascript_pack_tag and tried running the app - got the above error.
webpacker - version 3.5.5
rails - version 5.2.1
ruby - version 2.4.0p0
Running bin/webpack or bin/webpack-dev-serveryields
bin/webpack --log-level=debug
✖ 「command」: A webpack error occured while building: use --log-level=debug for more error detail
✖ 「command」: `[object Object]` is not an Option Object
➤ 「command」: TypeError: `[object Object]` is not an Option Object
at Object.module.exports (/Users/jseidel/dev/status321/node_modules/merge-options/index.js:156:10)
at distill (/Users/jseidel/dev/status321/node_modules/webpack-command/lib/config.js:16:16)
at loader.then (/Users/jseidel/dev/status321/node_modules/webpack-command/lib/config.js:58:22)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:118:7)
at Function.Module.runMain (module.js:692:11)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
When I load my app from http://localhost:3000, I get:
Processing by HomeController#index as HTML
Rendering home/index.html.erb within layouts/application
[Webpacker] Compiling…
[Webpacker] Compilation failed:
✖ 「command」: A webpack error occured while building: use --log-level=debug for more error detail
✖ 「command」: `[object Object]` is not an Option Object
Rendered home/index.html.erb within layouts/application (1316.7ms)
Completed 500 Internal Server Error in 1326ms (ActiveRecord: 0.0ms)
ActionView::Template::Error (Webpacker can't find ./components/body.js in /Users/jseidel/dev/status321/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:
{
}
):
1: <%= javascript_pack_tag './components/body'%>
app/views/home/index.html.erb:1:in _app_views_home_index_html_erb___1475153813720965089_70326716626020'
Not sure where to go from here, so would appreciate any suggestions on what to look for so I can resolve this issue. thanks much!
routes.rb has
root to home#index
app/javascript/src/components/ody.js has
<%= javascript_pack_tag './components/body'%> [I also tried it with just body but no love]
app/javascript/packs/application.js has
console.log('Hello World from Webpacker')
var componentRequireContext = require.context("components", true)
var ReactRailsUJS = require("react_ujs")
ReactRailsUJS.useContext(componentRequireContext)
but I do not see that console.log message
OK; I created a new rails app with --webpack=react in the creation and copied over my files. Now, webpacker creates a manifest file, but does not include my file... Any ffile that's in javascript/packs is included, and nothing else.
Next quetion: How do I get the files in my javascript/components/ directory added? My webpacker.yml has
source_path: app/javascript
which I thought would automatically handle this
All right -- figured it out.
webpacker.yml as distributed assumes that 'entry' modules are in app/javascript/packs. That's because of these two configuration lines
source_path: app/javascript
source_entry_path: packs
Once you have your main module here, it all works as expected. See this documentation (for anyone else that comes here)
By default, Webpacker ships with simple conventions for where the JavaScript app files and compiled webpack bundles will go in your Rails app. All these options are configurable from config/webpacker.yml file.
The configuration for what webpack is supposed to compile by default rests on the convention that every file in app/javascript/packs/*(default) or whatever path you set for source_entry_path in the webpacker.yml configuration is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside packs directory that you do not want to be an entry file. As a rule of thumb, put all files you want to link in your views inside "packs" directory and keep everything else under app/javascript.
Suppose you want to change the source directory from app/javascript to frontend and output to assets/packs. This is how you would do it:
config/webpacker.yml
source_path: frontend
source_entry_path: packs
public_output_path: assets/packs # outputs to => public/assets/packs
Could you help me out? I have the same problem but i can't solve it with this configuration. My problem is the same, i create a new rails application and the i start the server and i am able to see the home page of rails but then when i create a controller, view and new route then i get this error and until now the only way that i found to solve it was deleting this tag
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
I do not think this is an optimal solution
This is my 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: false
webpack_compile_output: true
# Additional paths webpack should lookup modules
# ['app/assets', 'engine/foo/app/assets']
resolved_paths: []
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false
# Extract and emit a css file
extract_css: false
static_assets_extensions:
- .jpg
- .jpeg
- .png
- .gif
- .tiff
- .ico
- .svg
- .eot
- .otf
- .ttf
- .woff
- .woff2
extensions:
- .mjs
- .js
- .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: false
# Extract and emit a css file
extract_css: true
# Cache manifest.json for performance
cache_manifest: true
This is my package,json
{
"name": "rails_app",
"private": true,
"dependencies": {
"@rails/ujs": "^6.0.0",
"turbolinks": "^5.2.0",
"@rails/activestorage": "^6.0.0",
"@rails/actioncable": "^6.0.0"
},
"version": "0.1.0"
}
This is the error:
Processing by CarsController#index as HTML
Rendering cars/index.html.erb within layouts/application
Car Load (2.8ms) SELECT "cars".* FROM "cars"
↳ app/views/cars/index.html.erb:16
Rendered cars/index.html.erb within layouts/application (Duration: 41.7ms | Allocations: 1437)
[Webpacker] Compiling...
[Webpacker] Compilation failed:
yarn run v1.19.1
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command "webpack" not found.
Completed 500 Internal Server Error in 1487ms (ActiveRecord: 9.5ms | Allocations: 11515)
ActionView::Template::Error (Webpacker can't find application in /home/yair/Desktop/JavaScript/RubyAndRails/Section3/rails_projects/rails_app/public/packs/manifest.json. Possible causes:
webpack -w or the webpack-dev-server.app/views/layouts/application.html.erb:9
After i delete the line 9 i got my project up and running, but i do not this this is the real solution.
I am using rails 6.0.2.1 and ruby 2.6.3
Try: yarn add webpack
Try:
yarn add webpack
yes, that worked for me
try: yarn add webpack where ?
try: yarn add webpack where ?
Type this command in your command terminal
Most helpful comment
Try:
yarn add webpack