Vanilla Rails 6.0: “error Command ”webpack“ not found”

江枫思渺然 提交于 2019-12-05 07:49:51

EDIT:

This is one of my first posts, so forgive me if I get the posting conventions wrong.

The problem comes from the version of node on your local computer. When you created your rails app, you probably had an error like this pop up:

The JavaScript app source directory already exists
   apply  /Users/mconiaris/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/webpacker-4.0.7/lib/install/binstubs.rb
  Copying binstubs
       exist    bin
      create    bin/webpack
      create    bin/webpack-dev-server
      append  .gitignore
Installing all JavaScript dependencies [4.0.7]
         run  yarn add @rails/webpacker from "."
yarn add v1.17.3
info No lockfile found.
[1/4] 🔍  Resolving packages...
warning @rails/webpacker > postcss-preset-env > postcss-color-functional-notation > postcss-values-parser > flatten@1.0.2: I wrote this module a very long time ago; you should use something else.
[2/4] 🚚  Fetching packages...
error get-caller-file@2.0.5: The engine "node" is incompatible with this module. Expected version "6.* || 8.* || >= 10.*". Got "9.4.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

In my case, I had version 9.4.0 of node installed on my computer, and that was the one version the get-caller-file package did not want to work with.

To fix the problem, first confirm your version of node to ensure that it's not 9.x.x:

node -v

Update node (I use nvm, but there are other ways on GitHub on the node Website).

nvm install node # "node" is an alias for the latest version

Check the version again. If it's 12.10 or higher, you should be all set.

Go start another brand new rails project and it should work fine.

Good luck!

I ended up removing yarn. After solving the error presented in this question, I had another problem with yarn. I don't know if I should cross-post my solution, since it is the same. or just link to it

https://stackoverflow.com/a/58100373/683982

Hope this helps someone

I had this problem on a fresh 6.0 install too, in my case it had nothing to do with node or yarn to my knowledge. I noticed there was no mention of webpack in package.json, so I ran yarn add webpack and tried again. I got the following that said it compiled, but the page still didn't load:

[Webpacker] Compiled all packs in /vagrant/revmtg/RevMtg/public/packs
[Webpacker] One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
 - webpack-cli (https://github.com/webpack/webpack-cli)
   The original webpack full-featured CLI.

So I ran yarn add webpack-cli. Then I got Error: Cannot find module '@rails/webpacker'.

So I deleted the node_modules folder and then ran bundle exec rails webpacker:install. After that it finally worked.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!