Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn --ignore-scripts causing issues #634

Closed
OliverJAsh opened this issue Mar 6, 2019 · 11 comments
Closed

Yarn --ignore-scripts causing issues #634

OliverJAsh opened this issue Mar 6, 2019 · 11 comments

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented Mar 6, 2019

At Unsplash we use the popular tool patch-package to apply patches to our Node modules after installation. This works in the form of a postinstall script.

However, this buildpack invokes yarn with the --ignore-scripts flag when pruning dev dependencies (since v119), which means patch-package will not run.

I can semi-understand why the buildpack would want to avoid invoking scripts, since the scripts were already run when yarn was invoked the first time, prior to building.

However, in this case we rely on scripts being invoked each time yarn is called, as they significantly modify the contents of node_modules. These modifications are needed for the app to run.

It feels like we need an option to opt-in to running scripts after pruning? Perhaps YARN_PRUNE_SCRIPTS 🤷‍♂️

@jmorrell
Copy link
Contributor

jmorrell commented Mar 6, 2019

I can semi-understand why the buildpack would want to avoid invoking scripts, since the scripts were already run when yarn was invoked the first time, prior to building.

This is needed because yarn does not provide a "prune" equivalent command. If someone were to kick off their build in postinstall they would end up running it twice, but it would fail the second time without devDependencies. The one we use was recommended in this issue: yarnpkg/yarn#696

https://yarnpkg.com/lang/en/docs/cli/prune/

I'm hesitant to add another script to support a niche workflow like this. Would adding an option to skip the prune step and letting you control this in a build script work for you?

Hand-wavy:

  "build": "yarn prune && patch-package"

@danielleadams
Copy link
Contributor

Hi @OliverJAsh, were you able to resolve this and use the patch-package module?

@OliverJAsh
Copy link
Contributor Author

I think we just resolved to keep dev dependencies (i.e. disable pruning).

Would adding an option to skip the prune step and letting you control this in a build script work for you?

Yeah I think so!

@OliverJAsh
Copy link
Contributor Author

Would adding an option to skip the prune step and letting you control this in a build script work for you?

This should already be possible via YARN_PRODUCTION="false", right?

@danielleadams
Copy link
Contributor

@OliverJAsh Sorry for the delay here. Yes, the buildpack will skip pruning with YARN_PRODUCTION=false, so that should fix your issue. This isn't ideal since now you aren't able to prune your dependencies.

Would adding a custom Heroku script at the end of the build be helpful? I think something like a heroku-cleanup would be helpful. I have been finding use cases where this would be helpful - so let me know what you think about this solution.

@OliverJAsh
Copy link
Contributor Author

That would be helpful. Another workaround I just thought it would be to run the cleanup in the Procfile, immediately before running the app.

@danielleadams
Copy link
Contributor

@OliverJAsh We've added a heroku-cleanup that runs after pruning and caching: https://devcenter.heroku.com/articles/nodejs-support#heroku-specific-build-steps. Please let me know if this solves your issue.

@danielleadams
Copy link
Contributor

Hi @OliverJAsh, just pinging again. I'd like to close this issue and want to make sure the solution we've provided fits the use case.

@OliverJAsh
Copy link
Contributor Author

Hi, sorry for missing your message. This is no longer a problem for us since we had to disable pruning of dev dependencies for other reasons, so I can't say whether it helps in our case, but maybe someone else who has faced this issue can help you?

@danielleadams
Copy link
Contributor

No problem - thanks for sharing. Going to go ahead and close this issue then.

@naiyt
Copy link

naiyt commented Nov 28, 2020

Just stumbled on this issue, and I can confirm that the new build steps work great. In the context of patch-package I'm now doing this:

  "scripts": {
    "postinstall": "patch-package",
    "heroku-postbuild": "patch-package"
  }

This properly patches both locally and on Heroku for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants