Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v9 run -r runs in wrong order #7997

Open
NiGhTTraX opened this issue Apr 23, 2024 · 4 comments
Open

v9 run -r runs in wrong order #7997

NiGhTTraX opened this issue Apr 23, 2024 · 4 comments

Comments

@NiGhTTraX
Copy link

Last pnpm version that worked

8.15.7

pnpm version

9.0.5

Code to reproduce the issue

  1. Clone https://github.com/NiGhTTraX/ts-monorepo.
  2. pnpm install
  3. pnpm run -r build

Expected behavior

All packages build in the correct topological order.

Actual behavior

packages/foo and packages/bar build in parallel. Since bar depends on foo it will fail to build.

Additional information

v8 run, foo builds first, then bar and others

Scope: 13 of 14 workspace projects
packages/foo build$ pnpm run clean && pnpm run compile
│ > @nighttrax/foo@1.0.0 clean ts-monorepo/packages/foo
│ > rimraf ./dist
│ > @nighttrax/foo@1.0.0 compile ts-monorepo/packages/foo
│ > tsc -p tsconfig.build.json
└─ Done in 778ms
apps/nestjs build$ nest build
└─ Running...
packages/bar build$ pnpm run clean && pnpm run compile
└─ Running...
apps/rollup build$ rollup -c --bundleConfigAsCjs
│ > @nighttrax/bar@1.0.0 clean ts-monorepo/packages/bar
└─ Running...
apps/rollup build$ rollup -c --bundleConfigAsCjs
│ > rimraf ./dist
└─ Running...
apps/rollup build$ rollup -c --bundleConfigAsCjs
│ 
│ src/index.tsx → ./dist....0.0 clean ts-monorepo/packages/components
│ created ./dist in 202ms
│ > @nighttrax/bar@1.0.0 compile ts-monorepo/packages/bar
└─ Running...
...

v9 run, foo and bar build in parallel

Scope: 13 of 14 workspace projects
packages/bar build$ pnpm run clean && pnpm run compile
│ > @nighttrax/bar@1.0.0 clean ts-monorepo/packages/bar
│ > rimraf ./dist
│ > @nighttrax/bar@1.0.0 compile ts-monorepo/packages/bar
│ > tsc -p tsconfig.build.json
│ src/index.ts(1,31): error TS2307: Cannot find module '@nighttrax/foo' or its corresponding type declarations.
│  ELIFECYCLE  Command failed with exit code 1.
└─ Failed in 830ms at ts-monorepo/packages/bar
packages/foo build$ pnpm run clean && pnpm run compile
│ > @nighttrax/foo@1.0.0 clean ts-monorepo/packages/foo
│ > rimraf ./dist
│ > @nighttrax/foo@1.0.0 compile ts-monorepo/packages/foo
│ > tsc -p tsconfig.build.json
└─ Done in 810ms
ts-monorepo/packages/bar:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  @nighttrax/bar@1.0.0 build: `pnpm run clean && pnpm run compile`
Exit status 1
 ELIFECYCLE  Command failed with exit code 1.

Process finished with exit code 1

Node.js version

20.11.0

Operating System

macOS

@gierschv
Copy link

+1, I have the same bug in one of my workspaces, worked perfectly with the last pnpm 8.15.7.

@nachoaldamav
Copy link
Contributor

nachoaldamav commented Apr 29, 2024

Hi! in the package.json of @nighttrax/bar, is there any reason the local dependency is not specified with the workspace: prefix? If it's for package publishing, you can use pnpm publish and pnpm will remove the prefix in the published package. (same with pnpm pack)

{
  "dependencies": {
    "@nighttrax/foo": "workspace:~1.0.0"
  }
}

With this change, in my side the command runs correctly (it has an error in a nextjs app, but does not seem related to pnpm). Thanks in advance!

EDIT:
The reason for the issue in the v9 update is a breaking change. More information here.
link-workspace-packages is now false by default.

@NiGhTTraX
Copy link
Author

NiGhTTraX commented Apr 29, 2024

@nachoaldamav thanks for spotting that, I guess it's just a relic from the beginning of the repo. Using the workspace: protocol does indeed fix the issue.

Regarding the link-workspace-packages breaking change, I think something else is breaking the behaviour of run -r. The lockfile suggests that the package is linked, and AFAICT pnpm i with v9 doesn't change that part of the lockfile while upgrading to the v9 format. Checking node_modules corroborates that. Moreover, building packages/foo manually before building packages/bar fixes the error, so it looks like an execution order problem with pnpm -r.

The use case from https://pnpm.io/workspaces fits my repo:

By default, pnpm will link packages from the workspace if the available packages match the declared ranges. For instance, foo@1.0.0 is linked into bar if bar has "foo": "^1.0.0" in its dependencies and foo@1.0.0 is in the workspace.

However, that only mentions linking, which seems to still work correctly in v9.

Since using workspace: fixes the problem, is there some other breaking change for v9 run -r that doesn't consider foo: ~1.0.0 a workspace dependency anymore?

Edit: hmm, setting link-workspace-packages=false makes run -r work as expected with v9. The docs seem misleading to me, as they talk about linking and node_modules, not about running scripts.

@gierschv
Copy link

EDIT: The reason for the issue in the v9 update is a breaking change. More information here. link-workspace-packages is now false by default.

@nachoaldamav Thanks for this, adjusting this option works for me 👍

I cannot switch (yet) to pnpm publish and workspace:* everywhere because semantic-release doesn't officially support pnpm to publish packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants