Compilation works locally but not on server.
It complains that /node_modules/.bin/webpackdoes not exist.
/bundle/ruby/2.5.0/gems/webpacker-4.0.0.pre.pre.2/lib/webpacker/webpack_runner.rb:11:in `exec': No such file or directory - /node_modules/.bin/webpack (Errno::ENOENT)
Globally speaking, how things are supposed to work?
node_modules/.bin/webpack?I've tried a whole bunch of things including https://github.com/rails/webpacker#upgrading
I'm using webpacker 4.0.0-pre.2
@olimart Where are you deploying? Heroku? Please make sure yarn install is run before asset compilation on production.
Own VPS.
I have a few apps. already deployed with the same script.
-----> Precompiling assets...
yarn install v1.7.0
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 18.62s.
Webpacker is installed 🎉 🍰
Using /home/deploy/yamail/releases/20180719190414/config/webpacker.yml file for setting up webpack paths
Compiling…
Compilation failed:
@olimart Any chance you have webpack listed under devDependencies in your package.json?
The output above looks fine to me, not sure why binary isn't there.
Who/when creates node_modules/.bin/webpack since it is gitignored?
You have to run yarn install before running asset precompilation
binstub bin/webpack does exist locally and is checked in git. Is there supposed to match node_modules/.bin/webpack?
Nope, this should be there if you have run yarn install (like it works locally)
Nope
{
"name": "yamail",
"private": true,
"dependencies": {
"@rails/webpacker": "^3.5.5",
"axios": "^0.18.0",
"babel-preset-react": "^6.24.1",
"prop-types": "^15.6.1",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-email-editor": "^0.8.1",
"stimulus": "^1.0.1",
"styled-components": "^3.3.2",
"webpack-cli": "^3.1.0"
},
"devDependencies": {
"webpack-dev-server": "^3.1.4"
}
}
What/where should I look on the server?
@gauravtiwari just noticed that Gemfile lists 4.0.0-pre.2 but Package.json has "@rails/webpacker": "^3.5.5"
Some command is overwritting Package.json though.
yarn add @rails/[email protected] and try a re-deploy.
Same.
Perhaps you should log into your VPS box shell and see if node_modues folder is created.
It gets created but is empty.
My script updates git folder then installs. What step is responsible to add files to it?
Could you please share your script?
In previous deployments sometimes it created yarn-integrity file but never bin folder.
echo '
-----> Installing gems...'
rbenv exec bundle install --path $DIR/shared/bundle --without development test --deployment
# Ruby on Rails
if grep -q '^ rails' Gemfile.lock; then
echo '
-----> Detected Rails app.'
# Comment this out if you'd like to use the database.yml in your repo
echo '
-----> Overwriting config/database.yml...'
echo "%{environment}:
adapter: %{database_adapter}
url: <%= ENV['DATABASE_URL'] %>
encoding: utf8
pool: 50
" > config/database.yml
echo '
-----> Overwriting config/cable.yml...'
echo "%{environment}:
adapter: redis
url: <%= ENV['REDIS_URL'] %>
" > config/cable.yml
if $WEB; then
echo '
-----> Precompiling assets...'
# Custom
echo '**********'
rbenv exec bundle exec rake yarn:install
echo '**********'
# End custom
rbenv exec bundle exec rake assets:precompile
fi
echo '
-----> Migrating database...'
rbenv exec bundle exec rake db:migrate
fi
# Update cron jobs if needed; whenever must be in your Gemfile
if ([ $CRON = true ] && [ -f config/schedule.rb ])
then
echo '
-----> Updating crontab...'
rbenv exec bundle exec whenever -i %{name} --update-crontab
fi
Just gonna leave a note here in case anyone else finds this in the future. A common cause of this is a missing bin/yarn binstub.
You'll want to add the following to your repo in bin/yarn
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec "yarnpkg", *ARGV
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end
And you'll want to set the executable flag on the file so it can be run.
git update-index --chmod=+x bin/yarn
@olimart why did you close this issue? did you manage to solve it after all? I'm having the exact same problem and even @excid3 suggestion didn't help :|
@feliperaul @excid3 suggestion did the trick.
I suggest that you upgrade dependencies, Webpacker 4 is around the corner for instance.
In my case, it happened because of package.json.
I moved the packages related to webpack, webpack-cli, and babel to devDependencies from dependencies.
And then I did the pre-compile so only the packages in the dependencies are installed.
So I moved the package back to dependencies, and it was fixed.
Check your package.json.
@excid3 's suggestion worked for me just now. Using Webpacker 3.5.3 after a rails upgrade to 5.2.4.1. 🎉
If someone finds this issue later on, I just got this fixed (on Rails6) running
rake webpacker:install
Most helpful comment
Just gonna leave a note here in case anyone else finds this in the future. A common cause of this is a missing
bin/yarnbinstub.You'll want to add the following to your repo in
bin/yarnAnd you'll want to set the executable flag on the file so it can be run.