Skip to content

extractMainLockfileDocument is broken on Windows #35828

@t3chguy

Description

@t3chguy

Current Behavior

Fails to extract the main document due to unexpected line endings.

Expected Behavior

Works the same way as Linux & macOS.

GitHub Repo

No response

Steps to Reproduce

  1. Use pnpm 11 with a multi-document lockfile
  2. Try to generate an nx graph

Nx Report

Report from dev machine, not affected CI.

 NX   Report complete - copy this into the issue template

Node           : 24.15.0
OS             : darwin-arm64
Native Target  : aarch64-macos
pnpm           : 11.2.2
daemon         : Available

nx             : 22.7.4
@nx/js         : 22.6.5
@nx/workspace  : 22.6.5
@nx/devkit     : 22.6.5
typescript     : 6.0.3
---------------------------------------
Community plugins:
@nx-tools/nx-container : 7.2.3
---------------------------------------
Cache Usage: 0.00 B / 92.64 GB
---------------------------------------
The following packages should match the installed version of nx
  - @nx/js@22.6.5
  - @nx/workspace@22.6.5
  - @nx/devkit@22.6.5

To fix this, run `nx migrate nx@22.7.4`
---------------------------------------
⚠️ Multiple Nx versions detected

Your workspace uses nx@22.7.4, but other packages depend on a different version:
  - @nx-tools/nx-container → @nx/devkit → nx@22.6.5

These packages should not have nx as a dependency. Please report this issue to the package maintainers.
Run `pnpm why nx@22.6.5` for more details.

Failure Logs

$ nx build -- "--publish" "never" "-w" "squirrel" "msi"
 NX   Failed to parse pnpm lockfile
Please open an issue at `https://github.com/nrwl/nx/issues/new?template=1-bug.yml` and provide a reproduction.
Original error: expected a single document in the stream, but found more
YAMLException: expected a single document in the stream, but found more
    at load (D:\a\element-web\element-web\node_modules\.pnpm\@zkochan+js-yaml@0.0.7\node_modules\@zkochan\js-yaml\lib\loader.js:1722:9)
    at parseAndNormalizePnpmLockfile (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\plugins\js\lock-file\utils\pnpm-normalizer.js:48:36)
    at parsePnpmLockFile (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\plugins\js\lock-file\pnpm-parser.js:28:73)
    at getPnpmLockfileNodes (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\plugins\js\lock-file\pnpm-parser.js:34:18)
    at getLockFileNodes (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\plugins\js\lock-file\lock-file.js:53:59)
    at internalCreateNodes (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\plugins\js\index.js:53:79)
    at D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\project-graph\plugins\utils.js:10:33
    at Array.map (<anonymous>)
    at createNodesFromFiles (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\project-graph\plugins\utils.js:8:35)
    at exports.createNodesV2 (D:\a\element-web\element-web\node_modules\.pnpm\nx@22.7.2\node_modules\nx\dist\src\plugins\js\index.js:27:51)
 NX   Failed to process project graph.
An error occurred while processing files for the nx/js/dependencies-and-lockfile plugin.
  - pnpm-lock.yaml:
      expected a single document in the stream, but found more
[ELIFECYCLE] Command failed with exit code 1.

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

// pnpm 11 writes a two-document lockfile when `managePackageManagerVersions` is
// enabled: the first document holds package-manager metadata, and the second
// holds the workspace lockfile. Mirror pnpm's own positional extraction so we
// always read the workspace document.
// https://github.com/pnpm/pnpm/blob/main/lockfile/fs/src/yamlDocuments.ts
function extractMainLockfileDocument(content: string): string {
if (!content.startsWith(YAML_DOCUMENT_START)) {
return content;
}
const separatorIndex = content.indexOf(
YAML_DOCUMENT_SEPARATOR,
YAML_DOCUMENT_START.length
);
if (separatorIndex === -1) {
return '';
}
return content.slice(separatorIndex + YAML_DOCUMENT_SEPARATOR.length);
}
cribs some of the code, but not enough to work on Windows. https://github.com/pnpm/pnpm/blob/main/lockfile/fs/src/yamlDocuments.ts#L31 namely is missing

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions