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] Preinstall script run after download dependencies #4067

Closed
2 tasks done
Bittttter opened this issue Nov 19, 2021 · 5 comments
Closed
2 tasks done

[BUG] Preinstall script run after download dependencies #4067

Bittttter opened this issue Nov 19, 2021 · 5 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@Bittttter
Copy link

Bittttter commented Nov 19, 2021

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When I execute npm install, It's download the dependencies first but not preinstall script.

Expected Behavior

  1. preinstall script run
  2. Download Dependencies as part of the install

Steps To Reproduce

  1. Touch a file named package.json with script setting "preinstall": "echo preinstall".
  2. Exec npm install in shell.
  3. Finally you can see that print after download all dependencies.

Environment

  • npm:8.1.4
  • Node:16.13.0
  • OS:macOS Monterey 12.0.1
  • platform:Macbook Pro
  • npm config:
; "user" config from /Users/edz/.npmrc

//registry-node.aliyun.com/org/1294702234938741/registry/xdk/:_password = (protected) 
//registry-node.aliyun.com/org/1294702234938741/registry/xdk/:username = "user_1294702425938741" 
//registry.npmjs.org/:_authToken = (protected) 
email = "bittttter@duduyixia.com" 
registry = "https://registry-node.aliyun.com/org/1294702234938741/registry/xdk/" 

; node bin location = /Users/edz/.nvm/versions/node/v16.13.0/bin/node
; cwd = /Users/edz/Documents/work/xdk-wechat-mini/xiaodaka-client
; HOME = /Users/edz
@Bittttter Bittttter added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Nov 19, 2021
@Bittttter
Copy link
Author

I'm confused, because of there had #2660 before. But it seemed for release 7.x, so I open this issue.

@microkof
Copy link

microkof commented Dec 3, 2021

I'm confused, because I found that this bug has existed since 2015, and it still exists today. Why?

@martin770
Copy link

I also have this problem. Last good npm version is 6.14.13, still broken in npm 8.5.0.

I have a dependency on a local package "myPackage": "file:./myPackage-0.1.0.tgz", and my preinstall script is setup to completely remove any old versions of that package before installing:
"preinstall": "rm -rf node_modules/myPackage && npm uninstall --no-save myPackage"

In npm 6.14.13, this works correctly by first wiping out myPackage before installing the dependencies.
preinstall -> install -> postinstall
In later versions (including 8.5.0), I can see the steps in the wrong order, which causes my module to be removed after install.
install -> preinstall -> postinstall

>npm --version
8.5.0
>npm install
... install happens here ...

> preinstall
> rm -rf node_modules/myPackage && npm uninstall --no-save myPackage

removed 8 packages in 973ms

> postinstall
> ./scripts/npm-postinstall.js

internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'myPackage'
Require stack:
- /home/me/scripts/npm-postinstall.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (/home/me/scripts/lib/@types.js:4:17)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/me/scripts/npm-postinstall.js'
  ]
}

I was following #2220, since that npm lifecycle bug also affected me. I can confirm that issue is fixed in 8.5.0 (postpack now runs in the correct order), but this issue still remains (preinstall still runs in the wrong order).

@wraithgar
Copy link
Member

Duplicate of #2660

@wraithgar wraithgar marked this as a duplicate of #2660 Mar 14, 2022
@master-zouyq
Copy link

it's time to use yarn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

5 participants