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

[Bug]: enableTransparentWorkspaces: false not respected, or dependency not installed #3518

Closed
1 task
nicolo-ribaudo opened this issue Oct 3, 2021 · 5 comments
Labels
bug Something isn't working reproducible This issue can be successfully reproduced

Comments

@nicolo-ribaudo
Copy link
Contributor

nicolo-ribaudo commented Oct 3, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

In the Babel repository (tested with commit https://github.com/babel/babel/tree/7bbdf096aa49f43909f559756e55127f831344f3), when running this script from the top-level:

const chain = [
  "jest",
  "@jest/core",
  "jest-snapshot",
  "@babel/traverse",
  "@babel/code-frame",
  "@babel/highlight",
  "@babel/helper-validator-identifier",
];
const len = chain.map(n => n.length).reduce((a, b) => Math.max(a, b));

let prev = process.cwd();
for (const name of chain) {
  prev = require.resolve(name, { paths: [prev] });
  console.log(`Resolve ${name.padEnd(len)} -> ${prev}`);
}

it logs this output:

Resolve jest                               -> /home/nicolo/Documenti/dev/babel/babel/node_modules/jest/build/jest.js
Resolve @jest/core                         -> /home/nicolo/Documenti/dev/babel/babel/node_modules/@jest/core/build/jest.js
Resolve jest-snapshot                      -> /home/nicolo/Documenti/dev/babel/babel/node_modules/jest-snapshot/build/index.js
Resolve @babel/traverse                    -> /home/nicolo/Documenti/dev/babel/babel/node_modules/jest-snapshot/node_modules/@babel/traverse/lib/index.js
Resolve @babel/code-frame                  -> /home/nicolo/Documenti/dev/babel/babel/node_modules/jest-snapshot/node_modules/@babel/traverse/node_modules/@babel/code-frame/lib/index.js
Resolve @babel/highlight                   -> /home/nicolo/Documenti/dev/babel/babel/node_modules/jest-snapshot/node_modules/@babel/highlight/lib/index.js
Resolve @babel/helper-validator-identifier -> /home/nicolo/Documenti/dev/babel/babel/packages/babel-helper-validator-identifier/lib/index.js

This is a valid dependency chain (jest depends on jest-snapshot, which depends on @babel/traverse, etc.) and we use enableTransparentWorkspaces: false: I expect the last @babel/helper-validator-identifier to be resolved to somewhere inside node_modules, and not to the monorepo package.

To reproduce

const { writeFile } = require("fs").promises;

await packageJson({
  name: "@babel/helper-validator-identifier",
  version: "7.40.0"
},{ cwd: "packages/babel-helper-validator-identifier" })

await writeFile(".yarnrc.yml", `
  nodeLinker: node-modules
  enableTransparentWorkspaces: false
`);
await writeFile("index.js", `
  const chain = [
    "jest",
    "@jest/core",
    "jest-snapshot",
    "@babel/traverse",
    "@babel/code-frame",
    "@babel/highlight",
    "@babel/helper-validator-identifier",
  ];

  let prev = process.cwd();
  for (const name of chain) {
    prev = require.resolve(name, { paths: [prev] });
  }
  module.exports = prev;
`);

await packageJsonAndInstall({
  workspaces: ["packages/babel-helper-validator-identifier"],
  dependencies: {
    jest: "^27.2.0"
  }
});

const result = await node("index.js");

expect(result).toBe("???");

Environment

System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 16.10.0 - /tmp/xfs-d2e13dcc/node
    Yarn: 3.0.2 - /tmp/xfs-d2e13dcc/yarn
    npm: 7.21.1 - ~/.npm-global/bin/npm

Additional context

This is causing the CI failure in babel/babel#13414

@nicolo-ribaudo nicolo-ribaudo added the bug Something isn't working label Oct 3, 2021
@yarnbot yarnbot added the reproducible This issue can be successfully reproduced label Oct 3, 2021
@yarnbot

This comment has been minimized.

2 similar comments
@yarnbot

This comment has been minimized.

@yarnbot
Copy link
Collaborator

yarnbot commented Oct 3, 2021

This issue reproduces on master:

Error: expect(received).toBe(expected) // Object.is equality

Expected: "???"
Received: {}
    at module.exports (evalmachine.<anonymous>:40:16)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:56:13
    at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:17:16)
    at async Object.executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:24:12)
    at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.2-91650a2501-627bee24a7.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:25:38)
    at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Command.js:161:26)
    at async Cli.run (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:74:24)
    at async Cli.runExit (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-91cf93ba72.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)

@nicolo-ribaudo
Copy link
Contributor Author

I don't know how to write the Sherlock example: how can I "extract" the result of the node script? I expected to see something like Received: "/path/to/somewhere", not Received: {}.

@nicolo-ribaudo
Copy link
Contributor Author

This seems to be fixed by #3438.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproducible This issue can be successfully reproduced
Projects
None yet
Development

No branches or pull requests

2 participants