Description
Current Behavior
When generating the lockfile I get an error:
Cannot destructure property 'data' of 'undefined' as it is undefined.
Expected Behavior
Pruned lockfile to be generated successfully.
Steps to Reproduce
- Add a dependency to a project using a ^ (or other semver specifier)
- Try generate a lockfile
- Boom
Nx Report
Node : 20.18.0
OS : darwin-arm64
Native Target : aarch64-macos
pnpm : 9.12.1
nx (global) : 20.0.1
nx : 20.0.5
@nx/js : 20.0.5
@nx/eslint : 20.0.5
@nx/workspace : 20.0.5
@nx/devkit : 20.0.5
@nx/esbuild : 20.0.5
@nx/eslint-plugin : 20.0.5
typescript : 5.6.3
Registered Plugins:
@nx/eslint/plugin
@nx/js/typescript
Failure Logs
TypeError: Cannot destructure property 'data' of 'undefined' as it is undefined.
at findOriginalKeys (/Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/plugins/js/lock-file/pnpm-parser.js:338:45)
at /Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/plugins/js/lock-file/pnpm-parser.js:421:50
at Array.forEach ()
at /Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/plugins/js/lock-file/pnpm-parser.js:409:47
at Array.forEach ()
at mapRootSnapshot (/Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/plugins/js/lock-file/pnpm-parser.js:407:7)
at stringifyPnpmLockfile (/Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/plugins/js/lock-file/pnpm-parser.js:281:26)
at createLockFile (/Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/plugins/js/lock-file/lock-file.js:168:60)
at runExecutor (/Users/jake/code/arkahna-platform/node_modules/.pnpm/@arkahna-accelerate+nx-containers@0.22.1@nx+devkit@2_mee46lnc3cz4fttde2yeyp7vu4/node_modules/@arkahna-accelerate/nx-containers/src/executors/docker-build/executor.js:49:50)
at runExecutorInternal (/Users/jake/code/arkahna-platform/node_modules/.pnpm/nx@20.0.5@swc-node+register@1.10.9_@swc+core@1.7.11__ga4jaomx6uf24wmwhpibcefami/node_modules/nx/src/command-line/run/run.js:98:19)
Additional Information
When using PNPM (maybe others) the lockfile generation creates a nodes
list, which is the exact available versions.
In my package.json I have entries like "tmp": "^0.2.3",
In nx/src/plugins/js/lock-file/pnpm-parser.js
there is this lookup:
const node = nodes[
npm:${packageName}@${version}] || nodes[
npm:${packageName}];
So it's looking for nodes['npm:tmp@^0.2.3'] || nodes ['npm:tmp']
, neither of which exist.
Possible fix:
const node = nodes[`npm:${packageName}@${version}`]
|| nodes[`npm:${packageName}`]
|| nodes[[`npm:](npm:${packageName}@${version.replace(/^~/, '')})`];
Or something like that to strip the specifier, that will at least fix the case of the matching version.
But likely we need to filter the nodes which start with npm:${packageName}
then match if the version is compatible with the range specified in the project package.json.
Or, just add to the parser.
if (!node) {
console.warn(`Could not find node for ${packageName}@${version} from ${depType}:${packageJson.name}@${packageJson.version}. Ensure you use exact version numbers in your package.json`);
return;
}