Replies: 1 comment
-
|
this is a classic pnpm strict mode + typescript resolution mismatch. the app probably runs fine because the bundler (wxt/vite) has its own module resolution, but the editor's typescript language server follows node's module resolution strictly and can't find the types through pnpm's symlink structure. the root causepnpm's strict even with fix 1: declare react where it's used (recommended)add {
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.1"
}
}then run fix 2: configure tsconfig properlyin your extension's {
"compilerOptions": {
"moduleResolution": "bundler",
"typeRoots": [
"./node_modules/@types",
"../../node_modules/@types"
],
"preserveSymlinks": false
}
}key points:
fix 3: ensure @types are publicly hoistedin public-hoist-pattern[]=*types*
public-hoist-pattern[]=*eslint*this hoists after changing rm -rf node_modules apps/gui/wefin-extension/node_modules
pnpm installmost likely fix for your casesince you already have
fix 1 + fix 2 together should solve it. links |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Workspace Structure
repo.wefin.ai/
├── apps/
│ └── gui/
│ └── wefin-extension/ # WXT-based Chrome extension
│ ├── package.json
│ └── pages/
│ └── home.tsx # Uses react
├── packages/
│ └── gui/
│ └── wefin/ # Shared UI component library
│ └── package.json
├── pnpm-workspace.yaml
├── .npmrc # shamefully-hoist=true
└── turbo.json
Problem Description
When i setup monorepo with pnpm + turbo . Ts-check always show cannot resolve the import {useState} from
reactmodule when imported although i have installed.The web app starts normally. However, I feel a bit annoyed because TypeScript check errors keep showing up in the code editor. I think this might be caused by pnpm hoisting. Is there any way to prevent these red errors from appearing?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions