webpacker is installed... ./bin/webpack: not found

Created on 13 May 2017  ยท  16Comments  ยท  Source: rails/webpacker

I'm not sure how to interpret this error that I get when trying to precompile assets on the server.
1) webpacker is installed
2) but webpack is not found
3) A JSON text must at least contain two octets! (thanks but which JSON file?)

app@vagrant:/var/www/app/application$ bundle exec rake assets:precompile
Webpacker is installed ๐ŸŽ‰ ๐Ÿฐ
Using /var/www/app/application/config/webpack/paths.yml file for setting up webpack paths
Compiling webpacker assets ๐ŸŽ‰
sh: 1: ./bin/webpack: not found
rake aborted!
JSON::ParserError: A JSON text must at least contain two octets!
/home/app/.rbenv/versions/2.3.1/bin/bundle:23:in `load'
/home/app/.rbenv/versions/2.3.1/bin/bundle:23:in `<main>'
Tasks: TOP => webpacker:compile
(See full trace by running task with --trace)

Most helpful comment

Doh. '~> 2.0'. I guess I assumed webpacker:install:react would bootstrap it all. Sorry for wasting your time.

All 16 comments

Perhaps you need to run yarn to get your dependencies loaded into node_modules.

@btc i just tried your suggestion but unfortunately it didn't work. i get the same error.

this line https://github.com/rails/webpacker/blob/master/lib/tasks/webpacker/compile.rake#L11
is allowed to execute after webpacker:verify_install succeeds. i'm wondering if webpacker:verify_install ought to have failed here, since a working webpack installation doesn't seem to be present? (even though i can run 'webpack' in the terminal and it works)

What's your rails version? Are you using rails 5? I think it's because you are lacking the binstub webpack in your bin folder.

And what's your webpacker's version?

@ytbryan you are right. i have a bin folder on my local machine but not on the remote server.

my webpacker version is 1.2, my rails version is 5.0.2 (i am blocked from upgrading to 5.1.0 by a dependency)

i ran bundle exec bin/rails app:update:bin and so now i have a bin folder.
i still get the same error though (there is no webpack binstub in the folder).

ok, so the problem seems to be that the auto-generated .gitignore file from rails 4.x has the bin folder in the .gitignore file. i'm going to play around with not .gitignoring the bin folder and see if that resolves the issue

the issue was caused by the bin folder not being present, and updating the .gitignore file and redeploying fixed it.

What's the solution for getting the webpack binstubs? in a rails 5.0.2 app? same as OP can't upgrade to 5.1 yet.
no ./bin in gitignore
ran yarn
bundle exec bin/rails app:update:bin runs no ./bin/webpack created
rails webpacker:install:react errors Webpack binstubs not found.

@raldred Did you run rails webpacker:install ? Which version of webpacker are you using?

Doh. '~> 2.0'. I guess I assumed webpacker:install:react would bootstrap it all. Sorry for wasting your time.

@raldred , same problem, I am assumed webpacker:install:react would auto generate all config files

I also experienced this issue while trying to add webpacker to an existing rails app.
The solution I used was to run the webpacker:installscript first
Then after that was done, I ran webpacker:install:react which added the files I needed.

Trying to run webpacker:install:react first caused the error that brought me here in the first place ๐Ÿ˜„

Running rails 4.2. I also had to
rake webpacker:install
before
rake webpacker:install:vue

I had this problem (.bin/webpack not found), but I think I had a different case. Turns out I wasn't npm installing the webpack commands. I added capistrano-npm to my deploy process and it works. Might help someone

I also has the same problem, and I reinstall

rails webpacker:install

many time >"<

I also having the issues.

Install webpack manually on your server:

  1. Add webpack to package.json โ€“ yarn add webpack webpack-cli;
  2. In your server go to a folder of current release, that was failed and do yarn:
cd /var/www/your_project/releases/your_release_timestamp
yarn
  1. Try to deploy โ€“ bundle exec cap production deploy
Was this page helpful?
0 / 5 - 0 ratings