[Bug?]: Typescript compiler cannot resolve dependencies if invoked inside a workspace
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
If using PnP as nodeLinker, the (patched) typescript compiler tsc is unable to resolve modules or type defintions if invoked inside a workspace. Therefore we are currently using the nodeLinker with the option βnode-modules" instead, however we would really like to upgrade towards the new pnp feature instead.
To reproduce
const {promises: {mkdir, writeFile}} = require(`fs`);
await mkdir(`app`);
await packageJsonAndInstall({
name: "parent",
packageManager: "[email protected]",
workspaces: [
"./app"
],
dependencies: {
"axios": "^0.27.2",
"typescript": "4.7.3"
}
});
await packageJsonAndInstall({
name: "child",
packageManager: "[email protected]",
peerDependencies: {
"axios": "",
"typescript": ""
},
devDependencies: {
"typescript": "4.7.3"
}
}, { cwd: "./app"});
await writeFile("index.ts", "import axios from 'axios';")
await writeFile(`app/index.ts`, "import axios from 'axios';")
await expect(yarn('workspace', 'parent', 'run', 'tsc', 'index.ts')).resolves.not.toThrowError("error TS2307: Cannot find module 'axios' or its corresponding type declarations.")
await expect(yarn('workspace', 'child', 'run', 'tsc', 'index.ts')).rejects.not.toThrowError("error TS2307: Cannot find module 'axios' or its corresponding type declarations.")
Environment
System:
OS: Windows 10 10.0.19044
CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Binaries:
Node: 16.15.1 - ~\AppData\Local\Temp\xfs-a5ca79a7\node.CMD
Yarn: 3.2.1 - ~\AppData\Local\Temp\xfs-a5ca79a7\yarn.CMD
npm: 8.11.0 - D:\Programme\npm.CMD
Local windows machine. But i used Sherlock Playground to provide a reproducible example
Additional context
No response
This issue reproduces on master:
Error: expect(received).rejects.not.toThrowError(expected)
Expected substring: not "error TS2307: Cannot find module 'axios' or its corresponding type declarations."
Received message: "Command failed: /usr/bin/node /github/workspace/scripts/actions/../run-yarn.js workspace child run tsc index.ts
index.ts(1,19): error TS2307: Cannot find module 'axios' or its corresponding type declarations.
"
at ChildProcess.exithandler (node:child_process:398:12)
at ChildProcess.emit (node:events:527:28)
at maybeClose (node:internal/child_process:1092:16)
at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
at Object.toThrowError (/github/workspace/.yarn/cache/expect-npm-24.8.0-8c7640c562-44ff9ab1e7.zip/node_modules/expect/build/index.js:242:20)
at module.exports (evalmachine.<anonymous>:35:80)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:57:13
at async executeInTempDirectory (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:18:16)
at async executeRepro (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/executeRepro.js:25:12)
at async ExecCommand.execute (/github/workspace/.yarn/cache/@arcanis-sherlock-npm-2.0.3-558f52b79f-286d94b96d.zip/node_modules/@arcanis/sherlock/lib/commands/exec.js:26:38)
at async ExecCommand.validateAndExecute (/github/workspace/.yarn/cache/clipanion-npm-2.0.0-rc.16-b9444aaf89-4061026d74.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-4061026d74.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-4061026d74.zip/node_modules/clipanion/lib/advanced/Cli.js:83:28)
i ran into this same issue when trying to upgrade to the latest version of typescript (4.7.4). i tested various versions to determine when the problem was introduced, and the first stable version of typescript that cannot resolve dependencies in my yarn workspaces is 4.7.2 (i.e. the first stable 4.7.x version). all 4.6.x versions i tested work fine, all the way through the latest stable 4.6, 4.6.4.
Just checking in, I'm also experiencing this issue and wondering if there's a potential fix or a path to fix?
This is working as expected, the child workspace doesn't declare axios as a (dev)dependency.
Peer dependencies need to be provided by the parent and in this case there isn't one.
Sorry, I thought this was related to #4903 which it was not.