Typescript error: TS2307 due to imports from `src` in type declarations
See original GitHub issueDescription
tsc
raises the type error TS2307 with following issues:
- Cannot find module ‘@chakra-ui/descendant/src/use-descendant’ or its corresponding type declarations
- Cannot find module ‘@chakra-ui/toast/src’ or its corresponding type declarations
- Cannot find module ‘@chakra-ui/theme/src/components’ or its corresponding type declarations
when compiling the project.
Affected packages:
Link to Reproduction
x
Steps to reproduce
Try to compile a typescript project (exact dependency versions and tsconfig provided below).
Chakra UI Version
2.0.0
Browser
x
Operating System
- macOS
- Windows
- Linux
Additional Information
tsconfig:
{
"compilerOptions": {
"strict": true,
"jsx": "react",
"module": "esnext",
"declaration": true,
"declarationDir": "types",
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"esModuleInterop": true
},
"exclude": ["dist", "node_modules"],
"include": ["src"]
}
related dependencies:
"typescript": "4.6.4",
"@chakra-ui/react": "2.0.0",
"@chakra-ui/system": "2.0.0",
"@chakra-ui/theme": "2.0.0",
"@chakra-ui/theme-tools": "2.0.0",
"@emotion/react": "11.9.0",
"@emotion/styled": "11.8.1",
"framer-motion": "6.3.3"
tsc output:
node_modules/@chakra-ui/accordion/dist/declarations/src/use-accordion.d.ts:7:25 - error TS2307: Cannot find module '@chakra-ui/descendant/src/use-descendant' or its corresponding type declarations.
7 descendants: import("@chakra-ui/descendant/src/use-descendant").UseDescendantsReturn;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@chakra-ui/menu/dist/declarations/src/use-menu.d.ts:9:25 - error TS2307: Cannot find module '@chakra-ui/descendant/src/use-descendant' or its corresponding type declarations.
9 descendants: import("@chakra-ui/descendant/src/use-descendant").UseDescendantsReturn;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@chakra-ui/pin-input/dist/declarations/src/use-pin-input.d.ts:6:25 - error TS2307: Cannot find module '@chakra-ui/descendant/src/use-descendant' or its corresponding type declarations.
6 descendants: import("@chakra-ui/descendant/src/use-descendant").UseDescendantsReturn;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@chakra-ui/react/dist/declarations/src/chakra-provider.d.ts:3:36 - error TS2307: Cannot find module '@chakra-ui/toast/src' or its corresponding type declarations.
3 import { ToastProviderProps } from "@chakra-ui/toast/src";
~~~~~~~~~~~~~~~~~~~~~~
node_modules/@chakra-ui/react/dist/declarations/src/chakra-provider.d.ts:14:39 - error TS2307: Cannot find module '@chakra-ui/theme/src/components' or its corresponding type declarations.
14 components: typeof import("@chakra-ui/theme/src/components");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@chakra-ui/tabs/dist/declarations/src/use-tabs.d.ts:8:25 - error TS2307: Cannot find module '@chakra-ui/descendant/src/use-descendant' or its corresponding type declarations.
8 descendants: import("@chakra-ui/descendant/src/use-descendant").UseDescendantsReturn;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is likely due to not exposing src
anymore in the resulting packages but still including the type declarations source.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
tsc throws `TS2307: Cannot find module` for a local file
ts(5,20): error TS2307: Cannot find module 'components/button'. It complains about all imports of local files, like the following: import Counter from ' ...
Read more >TIL: TypeScript | Fix "TS2307: Cannot find module 'src' or its ...
How to fix? error TS2307: Cannot find module 'src' or its corresponding type declarations.
Read more >TypeScript: Documentation - Module Resolution
In this case, the error would be something like error TS2307: Cannot find module 'moduleA'. Relative vs. Non-relative module imports. Module imports are ......
Read more >"TS2307: Cannot find module" error displayed while project ...
the problem is that the include pattern is specified incorrectly, thus no .ts files are included. As no tsconfig.json ts files are included...
Read more >error ts2307: cannot find module or its corresponding type ...
The error TS2307: Cannot find module or its corresponding type declarations generally occurs when you try to import a module or library that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve run into this issue as well but only after I updated my React version to 18. Thought I’d mention it.
@TylerAPfledderer
"skipLibCheck": true
is a workaround that works for the time being. It would be great if we can fix this since we’re relying on a few internal libraries and, in the long run, it’s not a great one for our use-case.I’d be happy to prepare a fix if I can have a bit of direction.