GithubHelp home page GithubHelp logo

Comments (15)

schneems avatar schneems commented on May 5, 2024 21

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.

cgarvis avatar cgarvis commented on May 5, 2024 2

No.

package.json

{}

yarn.lock

# trick heroku into installing yarn

from webpacker.

audionerd avatar audionerd commented on May 5, 2024 2

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 Heroku nodejs 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.

dhh avatar dhh commented on May 5, 2024 1

Fixed:

from webpacker.

dhh avatar dhh commented on May 5, 2024

from webpacker.

puneet-sutar avatar puneet-sutar commented on May 5, 2024

@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.

cgarvis avatar cgarvis commented on May 5, 2024

@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.

audionerd avatar audionerd commented on May 5, 2024

@cgarvis Are your fake package.json and yarn.lock at root level exact copies of those in vendor?

from webpacker.

audionerd avatar audionerd commented on May 5, 2024

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.

puneet-sutar avatar puneet-sutar commented on May 5, 2024

@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:

  1. Detect presence of vendor/yarn.lock and vendor/package.json
  2. 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).
  3. Install node_modules bin/yarn install
  4. Run rake webpacker:compile

from webpacker.

audionerd avatar audionerd commented on May 5, 2024

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.

puneet-sutar avatar puneet-sutar commented on May 5, 2024

@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.

codebryo avatar codebryo commented on May 5, 2024

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.

merqlove avatar merqlove commented on May 5, 2024

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.

benbonnet avatar benbonnet commented on May 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.