Experiencing issues with npm packages installation; runs with 'npm init xyz' but not with 'npm install'

I’m using the following versions:

  • Node: 16.20.2
  • NPM: 8.19.4
  • NVM: 0.39.7
  • Operating System: Amazon Linux 2

While attempting to set up a new playwright project with the command npm init playwright@latest – --ct, it successfully generates the packages and the package.json file. Although I receive a warning about the node version not being supported, everything seems to work correctly.

However, when I try to install the packages in a different environment using npm install, it fails due to a rollup version conflict, indicating that it expected version 0.21.4 but found 0.18.4 instead. This mismatch is causing issues since every time I work with git, the npm install command fails, forcing me to recreate the project with npm init. What could be causing this issue?

Hey Alice45,

This could be due to a version mismatch in your package-lock.json. Try the following steps:

  1. Delete node_modules and package-lock.json.
  2. Run npm cache clean --force to clear the npm cache.
  3. Update the rollup package version in package.json to match the expected one, if needed.
  4. Run npm install again.

This should help resolve the conflict.

Hi Alice45,

Building on what Bob_Clever suggested, another approach could be to assess the environment and dependencies in more detail to pinpoint the root of the discrepancy.

  1. Environment Consistency: Verify that both environments are consistent regarding Node and npm versions. Sometimes subtle differences in versions can cause unexpected behavior with dependencies.
  2. Package JSON Versions: Manually check for mismatches not only for the rollup but across your other dependencies by specifying exact versions (semantic versioning) in your package.json. This ensures that you are installing precisely the same versions across different environments:
    "dependencies": {
      "rollup": "0.21.4",
      "other-package": "version"
    }
  3. Utilize nvm: Use nvm to ensure consistent Node versions across different sessions easily. You can use
    nvm use 16.20.2
    to ensure you are always using the same Node version.
  4. Lockfile Maintenance: If you switch environments frequently, consider committing the package-lock.json file to keep consistency. However, remember it should reflect the updated correct dependencies.
  5. Verbose Logs: Finally, run npm install with --verbose to get detailed logs about what’s happening under the hood during installation. It will help you identify potential conflicts or network issues that aren't immediately obvious.

Through these steps, you’ll gain better control over your development environment and handle the package installations more reliably.