47

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
Robin Des Bois
  • 571
  • 1
  • 4
  • 6
  • downgrading the version of the node by using nvm helped, I downgraded from 20 to 16 now manifest is working fine. – vidur punj Aug 30 '23 at 13:48

20 Answers20

50

run the command

rails webpacker:install

This solved the problem for me.

Salman Haseeb Sheikh
  • 1,122
  • 2
  • 12
  • 20
39

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.

dandeto
  • 756
  • 6
  • 13
  • 2
    `bundle exec rails webpacker:clobber` removes the public/packs folder from the project, which contains the `public/packs/manifest.json` file, `yarn` brings it back. For anyone with the same problem, better use `clean-webpack-plugin`. – Karol Karol Nov 14 '20 at 10:58
  • After trying 430,123 different solutions this finally worked for me. Thanks! – zarathustra Mar 17 '23 at 15:20
16

Like Salman's answer above, the command

$ rails webpacker:install

or

$ bundle exec rails webpacker:install

solves the issue. Which is quite strange for me, as rails does not install webpacker automatically but includes the javascript_pack_tag in the default layout anyway. HOWEVER, if yarn complains about your node version, make sure to install the correct one and switch to it, then run the above command again. This simple thing took me an hour to figure out. For instance:

$ nvm install 13.7
$ nvm use 13.7
$ rails webpacker:install
Son Nguyen
  • 1,472
  • 8
  • 16
  • You save my life. Thanks! I think the yarn install command also is required, I don't remember – Juan Camilo Camacho Beltrán Jul 06 '21 at 20:26
  • Great answer - this worked for me! One minor difference is I went onto the Node.js home page to see what the latest version was, and installed it from there. Then I ran `rails webpacker:install`, and then everything worked fine. – nope2023 Dec 15 '21 at 22:37
10

I was experiencing this error for more time than I care to mention, until I ran the following steps:

First, webpacker was locked into version 4.0 in my Gemfile by default. I upgraded it to 5.0 and ran bundle update.

Then:

rm -rf node_modules
rails assets:clobber
yarn
rails assets:precompile

A new error appeared when precompiling assets:

yarn install v1.22.4
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.36s.
I, [2021-04-09T11:04:33.781374 #16062]  INFO -- : Writing /app/public/assets/manifest-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.js
I, [2021-04-09T11:04:33.781915 #16062]  INFO -- : Writing /app/public/assets/manifest-04024382391bb910584145d8113cf35ef376b55d125bb4516cebeb14ce788597.js.gz
Compiling...
Compilation failed:
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

So I edited config/webpack/environment.js file to read:

const { environment } = require('@rails/webpacker')

const customConfig = {
  resolve: {
    fallback: {
      dgram: false,
      fs: false,
      net: false,
      tls: false,
      child_process: false
    }
  }
};

environment.config.delete('node.dgram')
environment.config.delete('node.fs')
environment.config.delete('node.net')
environment.config.delete('node.tls')
environment.config.delete('node.child_process')

environment.config.merge(customConfig);

module.exports = environment

Only then could the javascript_load_tag be loaded. It may not work for everyone, but hopefully saves others time in the same circumstance.

benjessop
  • 1,729
  • 1
  • 8
  • 14
6

Here is my solution for future Rails 6.1+ and Ruby 2.7.1+ users.

For me it happened because my webpacker gem was set to a 4.0 version in the Gemfile. Once I raised it to a 5.0 version and ran bundle update, this error went away for me. It looks like webpacker may have been silently failing when it ran and never created the public/packs folder. Changing my Gemfile to the newest version of Webpacker solved this error for me.

Gemfile Changes

DELETED gem 'webpacker',    '~> 4.0.7'
ADDED   gem 'webpacker',    '~> 5.0'
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
CWarrington
  • 659
  • 5
  • 12
6

Running yarn add @rails/webpacker and afterwards rails webpacker:install solved the issue for me.

daktari
  • 91
  • 1
  • 8
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.

Henrik N
  • 15,786
  • 5
  • 82
  • 131
2

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)

Tyler Schroeder
  • 730
  • 3
  • 6
  • 14
2

I had the same issue and running: rails webpacker:compile fixed it

source: https://github.com/rails/webpacker/issues/2825#issuecomment-764888322

2

I was able to resolve this by running bundle exec rails webpacker:install this will generate a manifest.json file

1

I don't know if it's late but I battled with this for a while and after countless hours spent on research the only solution was to comment line 9 i.e the JavaScript tag which works and allows your code compile but you won't be able to run methods in your application (which utilizes javascript) bringing you back to square one. To solve this problem go to

"C:/Users/[...]/site_test/public"

and look for a packs folder. If the folder is not present then that is the problem.

Whenever your application runs it compiles and looks for all available files associated to the application.html.erb file and as such you have a stylesheet link tag (application.css) and a javascript link tag (application.js) the error is as a result of a missing application.js.

SOLUTION: TO SOLVE THIS create a packs folder in ("C:/Users/[...]/site_test/public/") your public folder and inside the packs folder create a manifest.json file. I.E

your-app-name/public/packs/manifest.json

After you've done all that, add the code below in your manifest.json file.

{
  "application.js": "/packs/js/application-e421b4aa3f716bebdab1.js",
  "application.js.map": "/packs/js/application-e421b4aa3f716bebdab1.js.map",
  "entrypoints": {
    "application": {
      "js": [
        "/packs/js/application-e421b4aa3f716bebdab1.js"
      ],
      "js.map": [
        "/packs/js/application-e421b4aa3f716bebdab1.js.map"
      ]
    }
  }
}

Hopefully that should do the trick

Godstrump
  • 74
  • 1
  • 1
  • 6
0

Thanks for your help. Unfortunately nothing works.

rails assets:clobber return "error Couldn't find an integrity file" immediately 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 ...

code_aks
  • 1,972
  • 1
  • 12
  • 28
Robin Des Bois
  • 571
  • 1
  • 4
  • 6
0

What solved this issue for me was downgrading nodejs to its stable version (I had accidentaly downloaded the latest instead), then create the new rails app again.

pablito.aven
  • 1,135
  • 1
  • 11
  • 29
0

This happened to me recently running Rails in the standard docker ruby container. Turns out I needed to add:

RUN apt-get update & apt-get install nodejs npm -y & npm install --global yarn

to my docker file in order to get anything past the initial rails smoketest screen to render.

Jared Chmielecki
  • 439
  • 4
  • 13
0

Nothing here would fix it for me. So I deleted the app and tried again, it worked after that. It seems like there is an install order. If you don't get it correct, it doesn't work.

DickieBoy
  • 4,886
  • 1
  • 28
  • 47
0

Update Node - >=12

my version - 16.13.1

Use webpacker from git -

gem 'webpacker', git: 'https://github.com/rails/webpacker.git'

move application.js from app/javascript/packs to app/javascript/

Stop the server, start This is weird. But this is working for me

prashantsahni
  • 2,128
  • 19
  • 20
0

It also happens when you have no yarn in your environment and try to use npm instead. Although packages can be installed by npm but webpacker requires yarn to run compiling tasks.

Sibevin Wang
  • 4,480
  • 3
  • 27
  • 27
0

Check your gitignore. You'll need to remove (or comment out) /public/packs

The manifest.json is located in /public/packs and if this folder and it's content are not included on production, webpacker won't be able to correctly route js and css files

0

Mine was fixed this way after trying lots of different things. My environment was

ruby 2.7.6 rails 6.1.7 node 18.14

I fixed mine by downgrading node to version 16 and running

./bin/webpack-dev-server # stackoverflow article below for more info

Error message "error:0308010C:digital envelope routines::unsupported"

Prior to the fix running webpack-dev-server manually showed the following errors

Error: error:0308010C:digital envelope routines::unsupported

bvsaker
  • 51
  • 5
-1

Fropd off somewhere. Empty Manifest. Error: Webpacker::Manifest::MissingEntryError in Welcome#index I jammed this in public/packs/manifest.json Now she speaks French.

{
  "application.js": "/packs/js/application-9afcbb5693aa87623e69.js",
  "application.js.map": "/packs/js/application-9afcbb5693aa87623e69.js.map",
  "entrypoints": {
    "application": {
      "js": [
        "/packs/js/application-9afcbb5693aa87623e69.js"
      ],
      "js.map": [
        "/packs/js/application-9afcbb5693aa87623e69.js.map"
      ]
    }
  }
}