mars/heroku-cra-node

Version using yarn instead of npm please?

invegat opened this issue · 6 comments

Version using yarn instead of npm please?
mars commented
  1. clone or fork this repo
  2. run yarn install
  3. commit the resulting yarn.lock lockfile
  4. deploy to Heroku

To run yarn at all with "git push heroku master" needed to git rm both package-lock.json files, haven't found any yarn replacement for "npm install --only=dev " of "heroku-postbuild": "cd react-ui/ && npm install && npm install --only=dev --no-shrinkwrap && npm run build

mars commented

If you move the entries in react-ui/package.json devDependencies to dependencies, then that dev deps command is not necessary, could be changed to:

"heroku-postbuild": "cd react-ui/ && yarn install && npm run build"

The whole reason that --only=dev --no-shrinkwrap exists is to work with the React app exactly as it's produced by create-react-app.

Wow, thanks, that worked.

Using all yarn also worked. "heroku-postbuild": "cd react-ui/ && yarn install && yarn build"

rokit commented

Here is how I incorporated yarn:

  • delete package-lock.json
  • run the yarn command. This creates the yarn.lock file so that Heroku knows you are using yarn. Without yarn.lock Heroku will try to use NPM instead and your build will fail.
  • under scripts: "heroku-postbuild": "cd react-ui/ && yarn --production=false && yarn build"
    yarn --production=false takes the place of npm install && npm install --only=dev --no-shrinkwrap. Not sure if --no-shrinkwrap is relevant to yarn. My test worked fine.

This way you can keep react-scripts as a dev dependency and use yarn as well.