Skip to content

Yarn lock v2 parser fails if there are no "dependencies" in package.json #276

@betalb

Description

@betalb

According to the code it parser, it is not verifying that dependencies field is actually present in package.json, which results in exception during test / monitor

https://github.com/snyk/nodejs-lockfile-parser/blame/9fc5d221f865e48096e4a0991e7c160836ddd68e/lib/aliasesPreprocessors/yarn-lock-v2.ts#L11C44-L11C56

2025-08-05T12:17:13.192Z snyk:run-test getDepsFromPlugin returned failed results, cannot run test/monitor [
  {
    targetFile: '/Users/***/yarn.lock',
    error: TypeError: Cannot convert undefined or null to object
        at Function.entries (<anonymous>)
        at rewriteAliasesInYarnLockV2 (/snapshot/project/dist/cli/webpack:/snyk/node_modules/snyk-nodejs-lockfile-parser/dist/aliasesPreprocessors/yarn-lock-v2.js:10:1)
        at Object.parseYarnLockV2Project (/snapshot/project/dist/cli/webpack:/snyk/node_modules/snyk-nodejs-lockfile-parser/dist/dep-graph-builders/yarn-lock-v2/simple.js:13:1)
        at buildDepGraph (/snapshot/project/dist/cli/webpack:/snyk/src/lib/plugins/nodejs-plugin/npm-lock-parser.ts:136:35)
        at Object.parse (/snapshot/project/dist/cli/webpack:/snyk/src/lib/plugins/nodejs-plugin/npm-lock-parser.ts:66:18)
        at Object.inspect (/snapshot/project/dist/cli/webpack:/snyk/src/lib/plugins/nodejs-plugin/index.ts:30:24)
        at Object.inspect (/snapshot/project/dist/cli/webpack:/snyk/src/lib/module-info/index.ts:23:33)
        at getSinglePluginResult (/snapshot/project/dist/cli/webpack:/snyk/src/lib/plugins/get-single-plugin-result.ts:15:64)
        at Object.getMultiPluginResult [as handler] (/snapshot/project/dist/cli/webpack:/snyk/src/lib/plugins/get-multi-plugin-result.ts:115:53)
        at getDepsFromPlugin (/snapshot/project/dist/cli/webpack:/snyk/src/lib/plugins/get-deps-from-plugin.ts:65:24)
        at assembleLocalPayloads (/snapshot/project/dist/cli/webpack:/snyk/src/lib/snyk-test/run-test.ts:641:18)
        at runTest (/snapshot/project/dist/cli/webpack:/snyk/src/lib/snyk-test/run-test.ts:370:22)
        at test (/snapshot/project/dist/cli/webpack:/snyk/src/cli/commands/test/index.ts:160:13)
        at runCommand (/snapshot/project/dist/cli/webpack:/snyk/src/cli/main.ts:58:25)
        at main (/snapshot/project/dist/cli/webpack:/snyk/src/cli/main.ts:361:11)
        at /snapshot/project/dist/cli/webpack:/snyk/src/cli/index.ts:13:3
        at callHandlingUnexpectedErrors (/snapshot/project/dist/cli/webpack:/snyk/src/lib/unexpected-error.ts:43:5),
    errMessage: 'Cannot convert undefined or null to object'
  }
]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions