1

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()?

1 Answer 1

1

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'));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, half works. The key is the change in paths. Typescript still cannot find import('@containers/Home') though, but, it can find as I originally had it: import('containers/Home')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.