moonrepo / moon

A build system and monorepo management tool for the web ecosystem, written in Rust.
https://moonrepo.dev/moon
MIT License
2.89k stars 157 forks source link

[bug] error with `yarn-deduplicate` on minimal build #1699

Open CluEleSsUK opened 2 days ago

CluEleSsUK commented 2 days ago

Describe the bug

Running a simple moon project:build throws an error about yarn-deduplicate not existing from inside yarn-deduplicate's code itself.

Steps to reproduce

my toolchain.yml is as follows:

node:
  version: 22.3.0
  packageManager: 'yarn'
  yarn:
    version: 1.22.22

my moon.yml for the project is as follows:

language: 'typescript'

tasks:
  build:
    command: 'yarn build'
    inputs:
      - 'lib/**/*'
      - 'src/**/*'
      - 'tsconfig.json'
      - 'package.json'
      - 'foundry.toml'
    outputs:
      - 'output'
      - 'artifacts'
      - 'typechain-types'
      - 'cache'
      - 'cache-hardhat'

The following is the build output:

me ~/r/myrepo (master) [1]> which yarn-deduplicate
/Users/me/.nvm/versions/node/v22.3.0/bin/yarn-deduplicate

me ~/r/myrepo (master)> moon myproject:build
▪▪▪▪ yarn install
yarn install (in ./myproject)
yarn install v1.22.22
warning ../../../package.json: No license field
[1/4] 🔍  Resolving packages...
success Already up-to-date.
$ husky && forge install
.git can't be foundUpdating dependencies in /Users/me/repos/myrepo/myproject/lib
✨  Done in 0.72s.
▪▪▪▪ yarn dedupe
Error: ENOENT: no such file or directory, open 'yarn-deduplicate'
    at Object.readFileSync (node:fs:448:20)
    at Object.<anonymous> (/Users/me/.nvm/versions/node/v22.3.0/lib/node_modules/yarn-deduplicate/dist/cli.js:34:35)
    at Module._compile (node:internal/modules/cjs/loader:1460:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1544:10)
    at Module.load (node:internal/modules/cjs/loader:1275:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:212:19)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:158:5)
    at node:internal/main/run_main_module:30:49 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'yarn-deduplicate'
}
Error: process::failed

  × Process /opt/homebrew/bin/fish failed: exit code 1

Expected behavior

my yarn build to run successfully (as it does when run on its own)

Environment

  System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 67.66 MB / 32.00 GB
    Shell: 3.7.1 - /usr/local/bin/fish
  Binaries:
    Node: 22.3.0 - ~/.nvm/versions/node/v22.3.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.3.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v22.3.0/bin/npm

Additional context

I have tried both fish and bash, and language: 'javascript'

milesj commented 1 day ago

I'm not entirely sure what's going on here.

In moon, yarn-deduplicate is ran through npx and doesn't rely on PATH. But it does look like it's actually hitting the correct path though? /Users/me/.nvm/versions/node/v22.3.0/lib/node_modules/yarn-deduplicate/dist/cli.js.

I'm guessing it's failing here? https://github.com/scinos/yarn-deduplicate/blob/master/src/cli.ts#L65

Is there a lockfile? Where is it located?

CluEleSsUK commented 1 day ago

indeed I can even open /Users/me/.nvm/versions/node/v22.3.0/lib/node_modules/yarn-deduplicate/dist/cli.js. There is a lockfile in the myproject dir but not myrepo (which is the root)

CluEleSsUK commented 1 day ago

though the fact it's looking for the file yarn-deduplicate in that directory and not yarn.lock seems suspicious

CluEleSsUK commented 1 day ago

I suspect the first arg here isn't necessary: https://github.com/moonrepo/moon/blame/9d4e5dc0b87dd8b741448c46de84495dd94e378e/legacy/node/tool/src/yarn_tool.rs#L218

though seems like it's been round a long time to have been broken without reporting

milesj commented 1 day ago

Unless npx changed how it's args work, that basically becomes: npx yarn-deduplicate yarn.lock.

I think the problem though that this may be running in the workspace root and not the project root. Let me dig further.

For now you can disable this till it works: https://moonrepo.dev/docs/config/toolchain#dedupeonlockfilechange

CluEleSsUK commented 1 day ago

I created a package.json at the root and created a yarn.lock but to no avail. Will disable for now - thanks!

CluEleSsUK commented 1 day ago

Hmm suspiciously it's still attempting to dedupe with the flag in my toolchain.yml

EDIT: npm seems to work fwiw

milesj commented 6 hours ago

I'm looking into this and haven't seen anything weird.

What's your npx version? I noticed you're using node v22, which is newer. Let me see if the APIs changed.

milesj commented 6 hours ago

Seems like npx has changed a bit since this was first built. Trying this: https://github.com/moonrepo/moon/pull/1701