seek-oss / playroom

Design with JSX, powered by your own component library.
MIT License
4.45k stars 183 forks source link

Error parsing static types when `moduleResolution` is set #236

Closed tmm closed 6 months ago

tmm commented 2 years ago

When moduleResolution is set in a tsconfig.json file, the following error below pops up. If you remove moduleResolution, then types are generated correctly and no error is thrown.

It would be great if you could provide a custom tsConfigPath or options to be spread into the first argument of withCompilerOptions.


$ playroom start
Error parsing static types.
Error: Debug Failure. Unexpected moduleResolution: Node
    at Object.resolveModuleName (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:41605:37)
    at loader_1 (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:111723:99)
    at loadWithLocalCache (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:111476:42)
    at actualResolveModuleNamesWorker (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:111724:129)
    at resolveModuleNamesWorker (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:111977:26)
    at resolveModuleNamesReusingOldState (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:112074:24)
    at processImportedModules (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:113532:35)
    at findSourceFileWorker (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:113333:17)
    at findSourceFile (/Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:113194:26)
    at /Users/tom/Code/ui/node_modules/typescript/lib/typescript.js:113146:85
ℹ 「wds」: Project is running at http://localhost:8082/
ℹ 「wds」: webpack output is served from undefined
ℹ 「wds」: Content not from webpack is served from /Users/tom/Code/ui
mogularpb commented 2 years ago

I am getting exactly the same error.

"playroom": "^0.27.0",
"typescript": "^4.4.2",
"webpack": "^4.46.0",

Node version is: v12.18.2

tmm commented 2 years ago

Would still be great to fix this, but thought of a temporary fix.

Since Playroom doesn't fully parse tsconfig.json (#241), you can set up tsconfig.json so it extends another configuration (tsconfig.base.json) that has moduleResolution set. This way moduleResolution is never picked up by Playroom, but editors and other tools are still able to read it.

tsconfig.json

{
  "extends": "./tsconfig.base.json"
}

tsconfig.base.json

{
  "compilerOptions": {
    ...
    "moduleResolution": "Node",
  },
  "include": ["./src/"],
  "exclude": ["node_modules"]
}
lucantini commented 2 years ago

I'm also having this problem with Playroom + TS. It complains about having moduleResolutions set to "node".

+1