问题
I'm creating a new rails application according to "Getting Started with Rails". The application starts normally in step 4.1. But when i create my first controller, i have a webpack error.
I'm new in webpack, i have red all documentation, but i don't understand what is wrong or missing...
- Windows 10 1903
- ruby 2.6
- rails 6.0.0
- nodeJS 12.11.0
rails webpacker:install
identical config/webpacker.yml
Copying webpack core config
exist config/webpack
identical config/webpack/development.js
identical config/webpack/environment.js
identical config/webpack/production.js
identical config/webpack/test.js
Copying postcss.config.js to app root directory
identical postcss.config.js
Copying babel.config.js to app root directory
identical babel.config.js
Copying .browserslistrc to app root directory
identical .browserslistrc
The JavaScript app source directory already exists
apply C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/install/binstubs.rb
Copying binstubs
exist bin
identical bin/webpack
identical bin/webpack-dev-server
append .gitignore
Installing all JavaScript dependencies [4.0.7]
run yarn add @rails/webpacker from "."
yarn add v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > webpack-dev-server@3.8.2" has unmet peer dependency "webpack@^4.0.0".
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ @rails/webpacker@4.0.7
info All dependencies
└─ @rails/webpacker@4.0.7
Done in 4.48s.
Installing dev server for live reloading
run yarn add --dev webpack-dev-server from "."
yarn add v1.17.3
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning "webpack-dev-server > webpack-dev-middleware@3.7.2" has unmet peer dependency "webpack@^4.0.0".
warning " > webpack-dev-server@3.8.2" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
success Saved 1 new dependency.
info Direct dependencies
└─ webpack-dev-server@3.8.2
info All dependencies
└─ webpack-dev-server@3.8.2
Done in 4.92s.
Webpacker successfully installed �🎉🍰🍰
Webpacker::Manifest::MissingEntryError in Welcome#index
Showing C:/Users/[...]/site_test/app/views/layouts/application.html.erb where line #9 raised:
Webpacker can't find application in C:/Users/[...]/site_test/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:
{
}
Extracted source (around line #9):
7
8 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9 <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10 </head>
11 <body>
12
回答1:
This error seems to be the key.
Your manifest contains:
{
}
Try simply running the yarn
command in your project directory. That should result in a manifest.json
file being created - among other things.
If that doesn't work, I found this issue on github from which I am verbatim reciting the following commands that may help you. This will reset all built assets and node_modules.
rm -rf node_modules
rails assets:clobber
yarn
rails assets:precompile
Check out that link for more information.
回答2:
run the command
rails webpacker:install
This solved the problem for me.
回答3:
I got this error message on a Rails 5.2 app where I added Webpacker per the instructions in its README.
After trying some other things, I tried starting webpacker-dev-server (even though it shouldn't be necessary) just to see if that would show a more helpful error. And it did:
$ ./bin/webpack-dev-server
warning package.json: No license field
Another program is running on port 3035. Set a new port in for dev_server
I then switched to another project I had running, which also uses Webpacker, and turned off its webpack-dev-server (just ctrl+c:ed the running server). Now when I reload a page in this new project, I no longer get the error. Even without me running webpack-dev-server manually.
You can change this port in config/webpacker.yml
, in the dev_server:
section. Don't forget to also update it in config/initializers/content_security_policy.rb
if necessary.
回答4:
I got this same error - fix for me: I had a NODE_ENV
environment variable set in my .zshrc
file that was causing the Webpack build to use the wrong environment config, unsetting that environment variable fixed it for me (unset NODE_ENV
)
回答5:
Thanks for your help. Unfortunately nothing works.
rails assets:clobber return "error Couldn't find an integrity file" immediatly after deleting node_modules folder. (Works after yarn install --check-files).
and rails assets:precompile return "C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/webpacker/webpack_runner.rb:23:in `exec': No such file or directory - C:\Users[...]\site_test\node_modules.bin/webpack (Errno::ENOENT)"
but i found what was wrong: the location in my computer! probably a name problem ...
来源:https://stackoverflow.com/questions/58270161/webpacker-cant-find-application