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

[BUG] Prepare script not running #2890

Closed
tejohnso opened this issue Mar 17, 2021 · 15 comments
Closed

[BUG] Prepare script not running #2890

tejohnso opened this issue Mar 17, 2021 · 15 comments
Assignees
Labels
Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release Wontfix this will not be worked on

Comments

@tejohnso
Copy link

I've searched a number of issues related to prepare but could not find quite the same scenario.

Current Behavior:

npm install does not run prepare script and does not install devDependencies

Expected Behavior:

npm install should run prepare script and install devDependencies

Steps To Reproduce:

  1. Create a private repo on github with a prepare script in the package.json file
  2. npm init -y in a local test folder
  3. npm install git+ssh://git@github.com:ghname/ghrepo#semver:^0.0.0
  4. Observe prepare script is not run

Environment:

OS: Arch Linux
NPM: 7.6.3
NODE: 15.11.0

@tejohnso tejohnso added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Mar 17, 2021
@ljharb
Copy link
Contributor

ljharb commented Mar 17, 2021

Dev deps should only be installed when running npm install with no arguments.

@tejohnso
Copy link
Author

If a package being installed through git contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed

That's not what I understand from the documentation

Also, even if a step 3a npm install is added, it still doesn't work.

@ljharb
Copy link
Contributor

ljharb commented Mar 17, 2021

ah, fair enough.

@nlf
Copy link
Contributor

nlf commented Mar 22, 2021

what is your prepare script doing? it's very likely it's running and we're just suppressing the output. one of the major changes in npm 7 is that we no longer display the results of lifecycle scripts at installation time in an attempt to reduce noise.

if, however, your prepare script is doing work like creating or modifying files and that modification isn't taking place, if you can give us a reproduction case with a real repo that would help a lot in addressing this for you.

@tejohnso
Copy link
Author

It's running npm run build which runs some compilation tasks, so I know it isn't running because the compiled files aren't created.

This is only happening in a private repo. Should I create one for testing purposes and invite you?

@sxn
Copy link

sxn commented May 3, 2021

Hi @nlf. I've encountered this bug as well, when using tarball dependencies. I've also created a repository to reproduce the issue: https://github.com/sxn/prepare-repro

@darcyclarke darcyclarke removed the Needs Triage needs review for next steps label May 14, 2021
@darcyclarke
Copy link
Contributor

This needs a bit more investigation our end; Potentially this is intentional but prioritizing accordingly (seems like v6 was doing this)

@darcyclarke darcyclarke added the Priority 1 high priority issue label May 14, 2021
@jcmonte
Copy link

jcmonte commented Sep 24, 2021

Any updates on this end? It'd be better to not have to downgrade to v6 for this feature.

@OmgImAlexis
Copy link

OmgImAlexis commented Dec 4, 2021

Confirmed this is 100% an issue #3800

This was also an issue in v6 #3800 (comment)

@ruyadorno ruyadorno self-assigned this Feb 22, 2022
@ruyadorno
Copy link
Contributor

ruyadorno commented Feb 24, 2022

hi @tejohnso thanks for taking the time to let us know about this issue 😊 I believe this issue has been fixed since then and it should no longer be the case in npm@8.5.2.

@sxn thanks for that repro, it was very useful while validating that everything is working as intended! it turns out that using full URLs like that tarball example is not going to trigger prepare steps, the extra work to run prepare scripts is intended for git-based dependencies only.

So in short npm needs to be aware the install is coming from a git repo in order to run prepare scripts. If you provide the full path to a remote tarball such as https://github.com/TryGhost/gatsby-plugin-advanced-sitemap/tarball/master the cli will interpret that as an already-prepared tarball and will not try to run any of the extra steps in order to prepare it.

I'm going to close this issue since everything is working as expecting as of npm@8.5.2 - Please feel free to open a new issue in case you find any other problem.

Thanks everyone!

@ruyadorno ruyadorno added Wontfix this will not be worked on and removed Bug thing that needs fixing labels Feb 24, 2022
@tejohnso
Copy link
Author

tejohnso commented Feb 25, 2022

@ruyadorno I don't see anything in the 8.5.2 release that would have fixed the issue and I'm still seeing it happen on 8.5.1. My dependency is of the form github:user/repo.git. The prepare script doesn't run and dependencies are not installed.

@ruyadorno
Copy link
Contributor

hi @tejohnso sorry to hear, in this case I'd ask you to please open a new issue providing much more info / details about your project setup and the repo you're trying to install. Ideally we need to reduce the bug to a minimal reproduction (an empty project with just a git repo dependency demonstrating the problem, similar to what @sxn did in this thread) in order to find out what the problem really is.

@tejohnso
Copy link
Author

tejohnso commented Mar 1, 2022

There's nothing special about the repo. I just set one up with npm init as described in the issue detail. I'll see if the same thing happens with a public repo, in which case I can save you the trouble of creating a repo to reproduce the issue.

@tejohnso
Copy link
Author

tejohnso commented Mar 1, 2022

@ruyadorno Maybe my expectations are off. From the documentation I see

NOTE: If a package being installed through git contains a prepare script, its dependencies and devDependencies will be installed, and the prepare script will be run, before the package is packaged and installed.

From this I expect that if A has dependency B, and dependency B has a prepare script in it, then npm install in A will install B and trigger its prepare script.

But later in the documentation, there's a new section that indicates "These are run from the scripts of <pkg-name>" and npm install isn't included there.

Can you clarify whether dependency Bs prepare script is supposed to run from an npm install in A?

@JounQin
Copy link

JounQin commented Nov 21, 2023

Why this issue is closed? I found no way to execute patch-package after npm install?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release Wontfix this will not be worked on
Projects
None yet
Development

No branches or pull requests

9 participants