Skip to content

Conversation

@olaservo
Copy link
Member

@olaservo olaservo commented May 1, 2025

Motivation and Context

Sometimes I run into errors related to a dependency that only gets resolved by deleting the package-lock.json and node_modules before running npm install again.

For example:

[0] Error: Cannot find module @rollup/rollup-win32-x64-msvc. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.

How Has This Been Tested?

The following examples were run without the npm install step to demonstrate that these files actually get deleted:

Tests on Windows:

Before:

image

image

image

image

After:

image

image

image

image

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

As a result of testing this script I ended up regenerating the package-lock.json, so it has a lot of changes. Most of these are just adding "resolved" URLs and "integrity" hashes as well as minor/patch updates to packages. Shouldn't be any breaking changes.

Copy link
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a few targets

package.json Outdated
"build-server": "cd server && npm run build",
"build-client": "cd client && npm run build",
"build-cli": "cd cli && npm run build",
"clean": "rimraf ./node_modules ./client/node_modules ./server/node_modules ./dist ./client/dist ./server/dist ./package-lock.json && npm install",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ./server/dist should be ./server/build
  • ./cli/build and ./cli/node_modules should also be included.
  • It might be an opportune time to rename ./server/build and ./cli/build to ./server/dist and ./cli/dist what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I made some changes to include the missed targets you called out. I think I'd prefer to keep the dist naming convention, unless you see a benefit to changing it? (Or is it just for consistency?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I made some changes to include the missed targets you called out. I think I'd prefer to keep the dist naming convention, unless you see a benefit to changing it? (Or is it just for consistency?)

Yeah, I like dist better, too. I was suggesting we could change the build folders to dist so that they'd all be the same.

Copy link
Member Author

@olaservo olaservo May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! I am in a 'if its not broken don't fix it' mood when it comes to these build files so how about we leave it as-is. I think another chance to revisit will come when I take a few things out of draft related to testing e2e (in a separate PR).

cliffhall
cliffhall previously approved these changes May 2, 2025
Copy link
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Fine to approve, unless you would like to do the build -> dist renaming and I'll review that if you do.

@olaservo olaservo marked this pull request as ready for review May 4, 2025 03:02
Copy link
Member

@cliffhall cliffhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@cliffhall cliffhall merged commit f05c27f into modelcontextprotocol:main May 5, 2025
2 checks passed
IgnacioC44 referenced this pull request in MCPJam/inspector Jun 21, 2025
Add npm clean script to simplify resetting dependencies
richardkmichael added a commit to richardkmichael/inspector that referenced this pull request Dec 5, 2025
The `--no-package-lock` workaround was added due to npm bug #4828, where
npm < 11.3.0 generates incomplete lockfiles for packages with optional
platform dependencies (esbuild, rollup).

Optional cross-platform dependencies were restored to
`package-lock.json` in 358f276, so npm will be able to install from the
lock file in the GitHub Actions.

Also, fixed in npm 11.3.0 (Apr 2025), but Node v22 ships npm v10 and
will remain affected out-of-the-box.

Investigation notes follow.

What happened?
--------------

1. Switch from yarn to npm: `package-lock.json` added, `yarn.lock` removed
  - modelcontextprotocol@702f827

  Presumably:
    - run `npm install` to generate a `package-lock.json` from the yarn-managed `node_modules`, on macos
    - bug #4828: npm omitted optional cross-platform dependencies from the lock file

2. Pull 47, tries `npm ci`, and reverts, on 11 Nov 2024
modelcontextprotocol@3789ef9
  - "Try restoring npm ci" --> testing the new node release for the bug?
  - ran against `setup-node`, `node-version: 18`, likely: 18.20.5 (released nov 11, 2024; ~same day)
    - git show 3789ef9:.github/workflows/main.yml

  - Failed action, and logs have expired
    - https://github.com/modelcontextprotocol/inspector/actions/runs/11782443393/job/32817472448

  - https://nodejs.org/en/download/archive/v18.20.5
    - uses npm 10.8.2

  - Re-tried in inspector fork
    - workflow run at 3789ef9
    - change `node-version: 18` to `18.20.5` (exact node / npm on commit date)
    - Fails due to missing `linux-x64-gnu` platform dep (rollup, would similarly affect esbuild)

3. Cross-platform dependencies restored to lockfile on 1 May 2025
modelcontextprotocol#372
  - modelcontextprotocol@358f276
  - worked because `package-lock.json` and `node_modules` were both removed
    - i.e., not the bug conditions -> even npm < 11.3.0 generates correct lockfile

  - At that point, `--no-package-lock` could've been removed from CI, Dockerfile, etc.

NPM
---

npm (aborist) fixed #4828
npm/cli#8184
  - npm/cli#4828 --> frequent http 500, due to many comments
  - npm/cli@a96d8f6
  - will not be backported

Released in 11.3.0 on 8 Apr
npm/cli#8150
  - https://github.com/npm/cli/releases/tag/v11.3.0
    - arborist 9.0.2
    - https://github.com/npm/cli/releases/tag/arborist-v9.0.2

  - npm v11.3.0 ships with node v24.2.0, on 6 May 2025
    - https://nodejs.org/en/download/archive/v24

Node v22 ships npm v10
  - https://nodejs.org/en/download/archive/v22
  - will always be affected, no backport coming
richardkmichael added a commit to richardkmichael/inspector that referenced this pull request Dec 6, 2025
The `--no-package-lock` workaround was added due to npm bug #4828, where
npm < 11.3.0 generates incomplete lockfiles for packages with optional
platform dependencies (esbuild, rollup).

Optional cross-platform dependencies were restored to
`package-lock.json` in 358f276, so npm will be able to install from the
lock file in the GitHub Actions.

Also, fixed in npm 11.3.0 (Apr 2025), but Node v22 ships npm v10 and
will remain affected out-of-the-box.

Investigation notes follow.

What happened?
--------------

1. Switch from yarn to npm: `package-lock.json` added, `yarn.lock` removed
  - modelcontextprotocol@702f827

  Presumably:
    - run `npm install` to generate a `package-lock.json` from the yarn-managed `node_modules`, on macos
    - bug #4828: npm omitted optional cross-platform dependencies from the lock file

  npm can't easily fix this.  `npm install foo@x.y.z` could write a
  resolved dependency, but at the exact version so `foo` would be pinned,
  and semver operator twiddling would be required to restore it as-was.

  The fix would be to "manually" re-add the missing metadata.

2. Pull 47, tries `npm ci`, and reverts, on 11 Nov 2024
modelcontextprotocol@3789ef9
  - "Try restoring npm ci" --> testing the new node release for the bug?
  - ran against `setup-node`, `node-version: 18`, likely: 18.20.5 (released nov 11, 2024; ~same day)
    - git show 3789ef9:.github/workflows/main.yml

  - Failed action, and logs have expired
    - https://github.com/modelcontextprotocol/inspector/actions/runs/11782443393/job/32817472448

  - https://nodejs.org/en/download/archive/v18.20.5
    - uses npm 10.8.2

  - Re-tried in inspector fork
    - workflow run at 3789ef9
    - change `node-version: 18` to `18.20.5` (exact node / npm on commit date)
    - Fails due to missing `linux-x64-gnu` platform dep (rollup, would similarly affect esbuild)

3. Cross-platform dependencies restored to lockfile on 1 May 2025
modelcontextprotocol#372
  - modelcontextprotocol@358f276
  - worked because `package-lock.json` and `node_modules` were both removed
    - i.e., not the bug conditions -> even npm < 11.3.0 generates correct lockfile

  - At that point, `--no-package-lock` could've been removed from CI, Dockerfile, etc.

NPM
---

npm (aborist) fixed #4828
npm/cli#8184
  - npm/cli#4828 --> frequent http 500, due to many comments
  - npm/cli@a96d8f6
  - will not be backported

Released in 11.3.0 on 8 Apr
npm/cli#8150
  - https://github.com/npm/cli/releases/tag/v11.3.0
    - arborist 9.0.2
    - https://github.com/npm/cli/releases/tag/arborist-v9.0.2

  - npm v11.3.0 ships with node v24.2.0, on 6 May 2025
    - https://nodejs.org/en/download/archive/v24

Node v22 ships npm v10
  - https://nodejs.org/en/download/archive/v22
  - will always be affected, no backport coming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants