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] gypfile:false no more honored #3341

Open
1 task done
adnan-kamili opened this issue Jun 1, 2021 · 8 comments
Open
1 task done

[BUG] gypfile:false no more honored #3341

adnan-kamili opened this issue Jun 1, 2021 · 8 comments
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 7.x work is associated with a specific npm 7 release

Comments

@adnan-kamili
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

We ship the compiled node addons with our npm package. To prevent npm from trying to build the package on npm install we set "gypfile":false in the package.json. It worked fine up to npm v6.x but doesn't work in npm v7.13.0.

If this is the new default behaviour and "gypfile":false is dropped altogether (like yarn doesn't honour this too), do we have any alternate way to prevent npm from building the package on npm install.

Expected Behavior

npm install should not attempt to rebuild the package when "gypfile":false

Steps To Reproduce

No response

Environment

  • OS: macOS 11.0
  • Node: 16
  • npm: 7.13.0
@adnan-kamili adnan-kamili 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 Jun 1, 2021
@nlf
Copy link
Contributor

nlf commented Jun 2, 2021

does your package specify an install (or preinstall) script that runs node-gyp?

looking at the code here if you have an install or preinstall script already specified, we will run them. we won't run an implicit node-gyp rebuild if you do not have an install or preinstall script and you specify "gypfile": false though.

i think this is a bug either way, but i'd like to confirm my assumption so we can be sure we fix this correctly.

@nlf nlf added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Jun 2, 2021
@adnan-kamili
Copy link
Author

adnan-kamili commented Jun 3, 2021

Here is the repo where the package exists:

https://github.com/cryptlex/lexactivator-js

To replicate the issue run npm install in the following sample:

https://github.com/cryptlex/lexactivator-js/tree/master/examples

It works fine in the case of npm 6.x but fails in npm 7.x.

@octopusjames
Copy link

octopusjames commented Jun 7, 2021

�I had the same issue and seems both 6.x and 7.x can't work. (version 6.14.11 and 7.16.0.)

Here is my package.json

{
    ...
    "gypfile": false,
    "scripts": {
        ...
        "preinstall": "node ./scripts/preinstall.js",  // just a placeholder to log something to console 
        ...
    },
    ...
}

OS: Windows 10 pro 20H2
Node: 14.16.0
npm: 6.14.11 and 7.16.0


Btw, is there any other workaround to disable node-gyp rebuild when npm install?
Many thanks!

@ewanharris
Copy link

@nlf I don't think this is coming from @npmcli/run-script but instead from @npmcli/arborist.

I looked at my install process under the debugger and tracked it down to here, at this point the pkg variable is a reduced version of my dependencies package.json, and is actually missing the scripts stanza (and also the gypfile like the original issue stated) so is using the default node-gyp rebuild always.

I forced it to take this path and refresh the package.json data and the install worked.

@ewanharris
Copy link

I was able to workaround this for now by manually reinstating the "hasInstallScript": true property onto the dependency in the package-lock.json file. It appears this had been removed while installing a new dependency causing the above, ref

@kgryte
Copy link

kgryte commented Aug 18, 2021

We're also wanting to disable native add-on compilation by setting gypfile: false in package.json files. Unfortunately, I cannot find anything in the npm docs explaining the expected behavior and whether gypfile: true|false is honored. Would be great if the public npm docs could explicitly clarify what should happen (preferably in the package.json docs).

@Planeshifter
Copy link

Following up on this, while most recent versions of npm on Linux do honor "gypfile": false in package.json files, we and our users have encountered aforementioned problem on Windows 10/11 with the latest npm versions 8.1.x down to 7.6.3. It would be great to get some clarification on whether the expected behavior of the gypfile field is intentionally left vague or whether the reported behavior will be treated as a bug.

@rotu
Copy link
Contributor

rotu commented Oct 11, 2023

I think this issue should be closed as fixed by 281a7f3. @Planeshifter is this still an issue on Windows? I opened a new issue for the missing package.json docs #6898.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

7 participants