Comments (15)
We are working on adding yarn to the buildpack for Rails right now on Heroku, so it won't work yet because we don't have the binaries in place.
from webpacker.
No.
package.json
{}
yarn.lock
# trick heroku into installing yarn
from webpacker.
The following worked for me:
In root Rails app folder:
package.json
{
"name": "app-name-here",
"description": "dummy package.json for heroku/nodejs buildpack support",
"private": true,
"engines": {
"node": "6.5.0",
"yarn": "0.18.1"
},
"scripts": {
"heroku-postbuild": "cd vendor && yarn"
}
}
yarn.lock
# Dummy yarn.lock to force heroku/nodejs to install yarn
Then add the nodejs
buildpack first, before ruby
buildpack:
$ heroku buildpacks:add --index 1 heroku/nodejs
Deploy
$ git push heroku master
Caveats:
- This creates an extra unused
node_modules
folder in Rails root when the Herokunodejs
buildpack runs the dummy install. - Heroku was confused when I added the
nodejs
buildpack to an existing Heroku app. Had to add/re-add ruby buildpack. Possibly a fluke with my config. https://devcenter.heroku.com/articles/buildpacks#detection-failure
from webpacker.
Fixed:
from webpacker.
from webpacker.
@cgarvis Did you also edit the heroku-ruby-buildpack to install node and yarn ? Or are you using some other solution.
I am using webpacker + react
I had to fork the heroku-ruby-buildpack and add code to do the following:
- Install node.
- Install yarn.
- Install node packages using yarn.
- run the
webpacker:compile
If the package.json
and yarn.lock
files were in the root folder(instead of vendor) I could have just used the https://github.com/heroku/heroku-buildpack-nodejs#yarn
which would have installed the packages for me and then added the code you have posted above in my codebase.
Thanks in advance for you help!
from webpacker.
@puneet-sutar I have multiple build packs heroku/ruby
and heroku/nodejs
. I have a fake package.json
and yarn.lock
file at the root level.
from webpacker.
@cgarvis Are your fake package.json
and yarn.lock
at root level exact copies of those in vendor
?
from webpacker.
Thanks @cgarvis.
I tried that approach, but got this error:
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: bundle exec rails webpacker:compile
remote: sh: 1: ./node_modules/webpack/bin/webpack.js: not found
remote: rails aborted!
I'm guessing this is because yarn
never ran in the vendor
folder, so vendor/node_modules
was empty when webpacker:compile
was called.
from webpacker.
@cgarvis @audionerd Nice tricks.
I had tried the fake package.json + yarn.lock + patching rake task to run bin/yarn install and web:compile approach works nicely.
I have also forked the heroku-ruby-buildpack and using it in my project now. If you want to give it a shot https://github.com/puneet-sutar/heroku-buildpack-ruby. Trying to get it merged(heroku/heroku-buildpack-ruby#521).
With this you just need 1 buildpack and don't need an fake files or patching tasks. It will do the following:
- Detect presence of vendor/yarn.lock and vendor/package.json
- If above files are present the download and install appropriate version of yarn an package.json(you can specify version as engines in package.json).
- Install node_modules
bin/yarn install
- Run
rake webpacker:compile
from webpacker.
Ah, I see – definitely makes more sense to run yarn
via that rake task vs in heroku-postbuild
. Like this example:
https://github.com/gauravtiwari/rails-webpacker/blob/master/lib/tasks/assets.rake
That patch looks great. It would be so nice to have yarn
installed by the Heroku ruby buildpack.
Not sure if it should be responsible for calling webpacker:compile
though, if it's easy enough to hook that into the existing assets:precompile
.
from webpacker.
@audionerd Just did not want to patch my rails App. Can always remove the webpacker:compile
once webpacker adds it to assets:precompile
.
from webpacker.
Not sure if this still helps, but for getting it running on Heroku, I did following:
- Set Buildpacks
heroku/nodejs
&heroku/ruby
- Create a fake
yarn.lock
( Thanks for the tip @cgarvis ) - Extend the Rakefile with:
Rake::Task['assets:precompile'].enhance do
system('bundle exec ./bin/yarn')
system('bundle exec rails webpacker:compile')
end
as I locally run the Rails app through foreman or in a Docker container I don't use the Rakefile elsewhere.
Will not be necessary anymore if both steps wander into the assets precompile step anyway :)
from webpacker.
Seems that yarn bug is fixed in master version.
I'm think different now, because i won't recompile packs from the outside of the current engine, so i decide to precompile it & and release within public/dist
folder. So any app that uses current engine can pick it up without dependencies 💩.
from webpacker.
Admitting you already have the npm modules installed, how one could still use assets:precompile with the ability to remove the yarn
command ? Just keep the effective build (the rails one and the webpack(er) one)
from webpacker.
Related Issues (20)
- Webpacker 6 Disable Babel HOT 1
- Webpacker compilation takes more than 1.5 hours HOT 11
- How do I allow a package in node_modules to be processed by babel? HOT 1
- Remove addition of node_modules to Rails.application.config.assets.paths HOT 1
- V6 Status HOT 3
- Raise an error when javascript_pack_tag or stylesheet_pack_tag are called more than once HOT 1
- Regular Expression Denial of Service in postcss HOT 2
- Intermittent Webpacker.dev_server.running? behavior HOT 2
- Host for assets from a webpacker configuration using custom domains not being resolved HOT 2
- Cherry-pick "Nothing to do" logging update onto `5.x` HOT 1
- Rails 6 WebPacker is not calling JQuery inside views HOT 1
- Security Vulnerability in [email protected] HOT 2
- currently no loaders are configured to process this file HOT 1
- Incompatibility with Ruby 3.2.0 HOT 2
- Confusing gem description on RubyGems HOT 1
- Npm package for 5.4.4 was not released HOT 2
- class variable @@local_levels of ActiveSupport::Logger is overtaken by Logger HOT 2
- Trying to deploy but assets assets:precompile fail
- Security Vulnerability for postcss
- Postcss Security Vulnerability
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpacker.