language-tools: Cannot find module XYZ or its corresponding type declarations.ts(2307)
What version of astro are you using?
2.5.0
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
pnpm
What operating system are you using?
Mac
What browser are you using?
Chrome
Describe the Bug
I have installed this package, but vscode throws an error when I import it in astro components, but it is working fine inside TSX files. See the screenshots below.
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 15 (4 by maintainers)
Anyone still with this issue? I’ve literally tried everything including having the astro files in include, but still error. it seems to be fine if it’s like one level down from src, but as soon as it’s deeper than that, it fails. It seems to be working again if restarting vs code, but it’s really annoying and thinking of just switching to something else if this prevails.
I believe there’s a lot of confusion here on what this issue is, some people are encountering this because Astro files are not included in their TypeScript project, which well, makes a lot of sense (we could most likely warn when that happens, for sure!), but is not really a bug.
Other are encountering this because they’re using
moduleResolution: 'node16'which, while it seems to work now, also is the wrong option to use with Astro. The files in (most parts) of your Astro projects are handled by a bundler, as such you should always be usingmoduleResolution: 'bundler'(which is what is included in all our presets)I’ll close this issue for now, since the node16 case has been resolved. If this happens again, please open another issue (with a reproduction.)
I have the same issue and created a repro repo.
A minimal build on my end requires a vite resolve alias and no
tsconfig.jsonat all.I need a
tsconfig.jsonwith configured paths, if i want to type-check withastro check, and it works just fine.I also have projects where the error does not occur. As of now I can’t explain why it is working in some projects but not in others.
Edit:
Fixed it by including astro files in the
tsconfig.json. I commited the fix in the repro repo.