Reputation: 24019
Folder structure:
src
- containers
- Home.tsx
I want to lazy load, so I'm trying:
const Home = React.lazy(() => import('containers/Home'));
VS Code shows 'containers/Home' as incorrect and when hovering over it complains:
Cannot find module 'containers/Home' or its corresponding type declarations.
I have paths set in tsconfig as:
"baseUrl": "./src",
"paths": {
"modules/*": [
"src/modules/*"
],
"containers/*": [
"src/containers/*"
]
}
Why does it not find containers/Home
when importing using React.lazy()
?
Upvotes: 1
Views: 763
Reputation: 100
set paths in tsconfig this way
"baseUrl": "src",
"paths": {
"@modules/*": [
"src/modules/*"
],
"@containers/*": [
"src/containers/*"
]
}
and use it like this
const Home = React.lazy(() => import('@containers/Home'));
Upvotes: 1