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

npm v7 support #7474

Closed
4 tasks
JamieMagee opened this issue Oct 15, 2020 · 36 comments
Closed
4 tasks

npm v7 support #7474

JamieMagee opened this issue Oct 15, 2020 · 36 comments
Labels
manager:npm package.json files (npm/yarn/pnpm) priority-2-high Bugs impacting wide number of users or very important features type:feature Feature (new functionality)

Comments

@JamieMagee
Copy link
Contributor

What would you like Renovate to be able to do?

Support the newly released npm v7. The blog post Presenting v7.0.0 of the npm CLI goes over some of the new features and breaking changes.

I'd like to use this issue as a mega-issue to discuss and co-ordinate npm v7 related changes to Renovate.

Did you already have any implementation ideas?

Some of the key features that will require Renovate changes:

  • package-lock.json v2

    I can't yet find a schema for this, but here's a good example

  • Workspaces

    See RFC 0026

  • npx

    npx has been completely rewritten to use the npm exec command. There are various changes in functionality, most noticeable being a prompt if the module you are trying to run is not yet installed.

    There are a few places we use npx, and we should make sure that we are calling npx non-interatively.

  • Peer dependencies

    Not sure if this one affects us

    Automatically installing peer dependencies (while this feature is something we think is desirable new behavior, it does potentially break certain workflows).

This list may not be complete.

The new library, @npmcli/arborist is also quite interesting, and should make interacting with the node_modules tree easier in future.

Are there any workarounds or alternative ideas you've tried to avoid needing this feature?

Switch to yarn 😂

Is this a feature you'd be interested in implementing yourself?

Yes, with assistance

@viceice viceice added type:feature Feature (new functionality) manager:npm package.json files (npm/yarn/pnpm) priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others labels Oct 15, 2020
@mccxiv
Copy link

mccxiv commented Oct 27, 2020

I'm here to express my confusion because we're already receiving PRs from renovate with "lockfileVersion": 2.
Is this already implemented?

@rarkins
Copy link
Collaborator

rarkins commented Oct 27, 2020

@mccxiv it's not intended. Can you reproduce the problem in a public repo? Does your engines allow node 15?

@mccxiv
Copy link

mccxiv commented Oct 27, 2020

I don't have a public repro for now

We use a monorepo on Gitlab. The top level package.json has:

"engines": {
    "node": ">= 10.0.0",
    "npm": ">= 5.6.0"
  },

The individual packages do not have an engines: field

The odd thing is some PRs don't use lockfile v2, and some do (see line diffs):

@Quramy

This comment has been minimized.

@rarkins

This comment has been minimized.

@rarkins
Copy link
Collaborator

rarkins commented Oct 27, 2020

I can reproduce it. If you have an engines that allows node 15, and no npm constraint limiting <7, then Renovate will run npm install using Node 15 which defaults to npm 7. Example log:

DEBUG: Found compatible npm version (repository=renovate-tests/npm42, branch=renovate/chalk-2.x)
       "constraint": ">=12",
       "version": "15.0.1"
DEBUG: Resolved tag constraint (repository=renovate-tests/npm42, branch=renovate/chalk-2.x)
       "image": "docker.io/renovate/node",
       "tagConstraint": ">=12",
       "tagVersioning": "npm",
       "tag": "15.0.1"

@rarkins
Copy link
Collaborator

rarkins commented Oct 27, 2020

I've experimented with using an npm constraint (e.g. npm i npm@^6.0.0) but it doesn't seem to downgrade the npm version in node 15.

@rarkins
Copy link
Collaborator

rarkins commented Oct 27, 2020

If you add the following to your renovate.json then it succeeds in getting Renovate to use node 14:

  "constraints": {
    "node": "< 15.0.0"
  }

Unfortunately it's only succeeding due to what seems like a bug, but it can work for now and be forwards compatible for anyone who wants to support node 15 in their engines without running it during Renovate PRs.

@Quramy

This comment has been minimized.

@rarkins
Copy link
Collaborator

rarkins commented Oct 27, 2020

Actually, the required config will be as following once #7561 is merged and live:

{
  "force": {
    "constraints": {
      "node": "< 15.0.0"
    }
  }
}

The force wrapper is necessary because otherwise the detected engines node constraint takes precedence.

@ylemkimon
Copy link
Contributor

ylemkimon commented Nov 12, 2020

@rarkins

I've experimented with using an npm constraint (e.g. npm i npm@^6.0.0) but it doesn't seem to downgrade the npm version in node 15.

Do you mean by setting

{
  "constraints": {
    "npm": "^6.0.0"
  }
}

?

In that case, it would haven't worked due to the cached location of npm after installing npm:

const npmCompatibility = config.constraints?.npm;
if (validRange(npmCompatibility)) {
installNpm += `@${quote(npmCompatibility)}`;
}

I opened a PR to fix the issue including automatically setting the constraints in #7700.

@ylemkimon
Copy link
Contributor

ylemkimon commented Nov 12, 2020

Workspaces seem to work out of the box: https://github.com/ylemkimon/npm-workspace.

  • npx

    npx has been completely rewritten to use the npm exec command. There are various changes in functionality, most noticeable being a prompt if the module you are trying to run is not yet installed.

    There are a few places we use npx, and we should make sure that we are calling npx non-interatively.

The only place npx is used is:

logger.debug('Performing yarn dedupe fewer');
commands.push('npx yarn-deduplicate --strategy fewer');
// Run yarn again in case any changes are necessary
commands.push(`yarn install ${cmdOptions}`.trim());
}
if (
(isYarn1 || isYarnDedupeAvailable) &&
config.postUpdateOptions?.includes('yarnDedupeHighest')
) {
logger.debug('Performing yarn dedupe highest');
if (isYarn1) {
commands.push('npx yarn-deduplicate --strategy highest');

@ylemkimon
Copy link
Contributor

npx will also work out of the box, i.e., non-interactively, because we set CI=true:

const extraEnv: ExecOptions['extraEnv'] = {
NPM_CONFIG_CACHE: env.NPM_CONFIG_CACHE,
npm_config_store: env.npm_config_store,
CI: 'true',

and npm 7 detects it: https://github.com/npm/cli/blob/a28aff769a77f127f371c31afcb9e9814722e5cd/lib/exec.js#L190-L191

I think we can say Renovate has full support for npm 7.

@stephenwade
Copy link
Contributor

stephenwade commented Nov 29, 2020

#7700 adds support for npm 7 in Docker, but npm 6 is still used when run locally (npm i -g renovate). Is there any way to get Renovate to use npm 7 (or get it to use my globally installed npm instead of the bundled npm) when running locally?

EDIT: npm 6 is only used when in local development. Globally installed renovate will properly use your globally installed npm version.

@viceice
Copy link
Member

viceice commented Nov 29, 2020

Looks like this is a technical limitation, as yarn / npm always prefer local bin before global.

Maybe we need to migrate away from referencing the full npm package.

@stephenwade
Copy link
Contributor

Renovate doesn't reference npm directly, but semantic-release does so it still ends up in the local bin folder.

@stephenwade
Copy link
Contributor

Are there any config options to specify the path to npm?

@viceice
Copy link
Member

viceice commented Nov 29, 2020

Semantic release is a dev dependency and shouldn't be installed on production. 🤔

@viceice
Copy link
Member

viceice commented Nov 29, 2020

Are there any config options to specify the path to npm?

Nope

@stephenwade
Copy link
Contributor

Okay, I found my issue. I was testing with a local dev build which is why I had npm@6 in that folder. When I run the globally installed renovate, it uses my globally installed npm version.

@ylemkimon
Copy link
Contributor

ylemkimon commented Nov 30, 2020

@viceice
Copy link
Member

viceice commented Feb 9, 2021

I think we properly support npm v7 now. 🤔

I'll close this, feel free to reopen or open a new issue / discussion if there are any problems.

@viceice viceice closed this as completed Feb 9, 2021
@viceice viceice added status:ready and removed status:requirements Full requirements are not yet known, so implementation should not be started labels Feb 9, 2021
@rarkins
Copy link
Collaborator

rarkins commented Feb 9, 2021

I think we're missing workspaces, but let's handle that in a separate issue and get a reproduction for it

@abernix
Copy link
Contributor

abernix commented Mar 8, 2021

🤔 It seems that, despite having engines.npm set to a 6.x range, that the attempt to update is still happening with npm 7:

From apollographql/apollo-server#4998 (comment):

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: undefined,
npm WARN EBADENGINE   required: { node: '>=6 <15', npm: '^6.14.11' },
npm WARN EBADENGINE   current: { node: 'v14.16.0', npm: '7.6.1' }
npm WARN EBADENGINE }

Is there another way that this is meant to be configured/conveyed?

@rarkins
Copy link
Collaborator

rarkins commented Mar 8, 2021

@abernix please create a new bug report issue and locate the relevant job logs from app.renovatebot.com. We'd want to see any mentions of constraints in the logs as well as see the debugging prior to the docker run command being executed.

@abernix

This comment has been minimized.

@HonkingGoose

This comment has been minimized.

@rarkins
Copy link
Collaborator

rarkins commented Mar 8, 2021

Can you try again now? I restarted the API process and I think that's cleared it

@abernix

This comment has been minimized.

@gremo
Copy link

gremo commented Mar 10, 2021

Hi, for me "force" seems not to work.

Renovate is still creating PR with NPM version 7 (see gremo/nest-winston@4f8ddb8). Any help is much appreciated!

{
  "extends": [
    "config:base",
    ":disablePeerDependencies"
  ],
  "packageRules": [
    {
      "depTypeList": [
        "devDependencies"
      ],
      "rangeStrategy": "bump"
    }
  ],
  "force": {
    "constraints": {
      "node": "< 15.0.0"
    }
  }
}

@JamieMagee
Copy link
Contributor Author

@gremo Can you please open a new issue, or comment on an existing open issue. @abernix's issue #9036 appears to be relevant.

@gremo
Copy link

gremo commented Mar 12, 2021

@JamieMagee thanks created a new issue #9103. Hope I find where the problem is.

@rarkins
Copy link
Collaborator

rarkins commented Mar 12, 2021

It's the same scenario as for @abernix - forced constraints with node only now don't stop npm@latest from being installed.

@gremo
Copy link

gremo commented Mar 12, 2021

Thanks @rarkins, so... what's the proposed / working solution?

@viceice
Copy link
Member

viceice commented Mar 12, 2021

@gremo Do not use the force constraints and let the renovate's magic work.

Als long there is a v1 lockfile, renovate will force node v14 and npm v6.

donmahallem added a commit to manniwatch/manniwatch that referenced this issue Apr 10, 2021
donmahallem added a commit to donmahallem/guenni that referenced this issue Apr 10, 2021
donmahallem added a commit to donmahallem/guenni that referenced this issue Apr 10, 2021
* chore(deps): set use legagy peer deps to true

Fixes issues related to renovatebot/renovate#7474

* chore: track npmrc changes
mergify bot pushed a commit to manniwatch/manniwatch that referenced this issue Apr 10, 2021
donmahallem added a commit to donmahallem/donmahallem.github.io.source that referenced this issue Apr 10, 2021
donmahallem added a commit to spielhalle/spielhalle that referenced this issue Apr 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
manager:npm package.json files (npm/yarn/pnpm) priority-2-high Bugs impacting wide number of users or very important features type:feature Feature (new functionality)
Projects
None yet
Development

No branches or pull requests

10 participants