How to get pnpm to interact nicely with tsc/vue-tsc without turning on shamefullyHoist? #10521
-
|
Moving a project from npm to pnpm, I'm now dealing with the rite of passage that is learning whether I can do without The gist is that and setting
SetupHost projectLet's start with a minimal host project definition that only lists
{
"scripts": {
"type-check": "npx vue-tsc --build"
},
"dependencies": {
"direct-dep": "*"
}
}This host project would have some code that uses
import { directFn } from 'direct-dep/module.js'
directFn()direct-depThe direct-dep package in turn only lists
{
"files": ["module.js"],
"dependencies": {
"transitive-dep": "1.2.3"
}
}The
import { fn } from 'transitive-dep'
export function directFn() {
fn()
}Note in particular, that DependenciesAs far as I understand, that is the correct way to declare the dependencies involved. Specifically, host-project shouldn't have But then how come tsc isn't able to resolve the
The last point in particular is strange: Shouldn't I should also say that this exact setup doesn't cause any problems with vite's development server, vitest node-based testing, playwright browser-based testing or ESLint; it's only tsc that doesn't manage to resolve the module. Still, I'm unsure what to do about it short of, well, turning |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
@kleinfreund the issue is that the targeted fix is public-hoist-pattern[]=@problematic/transitive-dep
public-hoist-pattern[]=@types/whatever-is-missingthis hoists only those specific packages to the root alternatively, just add the missing transitive deps as explicit one important note from the pnpm typescript docs: do NOT set if neither of those work, |
Beta Was this translation helpful? Give feedback.
@kleinfreund the issue is that
vue-tscuses TypeScript's standard module resolution, which doesn't understand pnpm's.pnpmsymlink structure. vite/vitest have their own enhanced resolution that follows these symlinks. tsc doesn't.the targeted fix is
public-hoist-patternin.npmrcfor just the problematic transitive deps:this hoists only those specific packages to the root
node_modules/where tsc can find them. it's a scalpel vsshamefullyHoist's sledgehammer.alternatively, just add the missing transitive deps as explicit
devDependencies. if tsc needs to resolve them for type-checking, t…