nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.58k stars 2.36k forks source link

NX cannot create the package-lock.json file #20780

Closed j1mmie closed 5 months ago

j1mmie commented 10 months ago

Current Behavior

npx nx build fails when using a project with npm module @dplusic/gamelift-nodejs-serversdk installed

Expected Behavior

npx nx build should succeed

GitHub Repo

No response

Steps to Reproduce

1.npm install @dplusic/gamelift-nodejs-serversdk

  1. npx nx build

Nx Report

Node   : 16.20.2
   OS     : darwin-x64
   npm    : 8.19.4

   nx             : 17.1.3
   @nx/js         : 17.1.3
   @nx/jest       : 16.10.0
   @nx/linter     : 17.1.3
   @nx/eslint     : 17.1.2
   @nrwl/linter   : 16.10.0
   @nx/workspace  : 17.1.3
   @nx/devkit     : 17.1.3
   @nx/esbuild    : 17.1.3
   @nx/node       : 16.10.0
   @nx/plugin     : 17.1.2
   @nrwl/tao      : 17.1.3
   typescript     : 5.2.2
   ---------------------------------------
   Community plugins:
   @simondotm/nx-firebase : 2.1.2
   ---------------------------------------
   The following packages should match the installed version of nx
     - @nx/jest@16.10.0
     - @nrwl/jest@16.10.0
     - @nx/eslint@17.1.2
     - @nrwl/linter@16.10.0
     - @nx/node@16.10.0
     - @nrwl/node@16.10.0
     - @nx/plugin@17.1.2
     - @nrwl/nx-plugin@17.1.2

   To fix this, run `nx migrate nx@17.1.3`

Failure Logs

> npx nx build functions

   ✔    3/3 dependent project tasks succeeded [0 read from cache]

   Hint: you can run the command with --verbose to see the full dependent project outputs

 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

> nx run functions:build

 >  NX   An error occured while creating pruned lockfile

   Please open an issue at `https://github.com/nrwl/nx/issues/new?template=1-bug.yml` and provide a reproduction.
   To prevent the build from breaking we are returning the root lock file.
   If you run `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.

Original error: Cannot read properties of undefined (reading 'dependencies')

   TypeError: Cannot read properties of undefined (reading 'dependencies')
    at getPackageParent (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/nx/src/plugins/js/lock-file/npm-parser.js:269:17)
    at /Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/nx/src/plugins/js/lock-file/npm-parser.js:259:9
    at Array.forEach (<anonymous>)
    at mapV1Snapshots (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/nx/src/plugins/js/lock-file/npm-parser.js:258:20)
    at stringifyNpmLockfile (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/nx/src/plugins/js/lock-file/npm-parser.js:243:31)
    at createLockFile (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/nx/src/plugins/js/lock-file/lock-file.js:134:58)
    at updatePackageJson (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/@nx/js/src/utils/package-json/update-package-json.js:44:57)
    at copyPackageJson (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/@nx/js/src/utils/package-json/index.js:26:53)
    at esbuildExecutor (/Users/jimmie/GameDev/Slipstream/Game/SlipstreamServers/node_modules/@nx/esbuild/src/executors/esbuild/esbuild.impl.js:65:60)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Package Manager Version

No response

Operating System

Additional Information

Similar to https://github.com/nrwl/nx/issues/15856

An easy way to avoid the error is to add the following code to line 269 of npm-parser.js:

if (!parent) {
  return {}
}

But I'm not sure what the side effects of that are. I will try to create a repro repository for this issue as soon as I can

jaysoo commented 10 months ago

Thanks for reporting, we'll look into it.

meeroslav commented 5 months ago

Hi @j1mmie, I know it's been a while, but if you are still experiencing this issue, please provide a small repo where this can be reproduced.

I tried adding it on the repo from https://github.com/nrwl/nx/issues/15856 but everything is being parsed properly.

In the meantime, I will close this issue.

github-actions[bot] commented 4 months ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.