react lazy component alias import is not work
Describe the bug
When I use lazy api, is not work
like it

Reproduction
https://stackblitz.com/edit/vitejs-vite-j2nqg5?file=src/main.tsx
System Info
System:
OS: macOS 11.5
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Memory: 2.00 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
Yarn: 1.19.1 - /usr/local/bin/yarn
npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
npmPackages:
@vitejs/plugin-react: ^1.3.0 => 1.3.2
vite: ^2.9.7 => 2.9.8
Used Package Manager
pnpm
Logs
No response
Validations
- [ ] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
It's a limitation of @rollup/dynamic-import-vars as you can see with the warning.
The above dynamic import cannot be analyzed by vite.See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.
FYI workStr does not work after build.
For example, the code below would work instead.
const Component = lazy(() => import('@/App'));
It's a limitation of
@rollup/dynamic-import-varsas you can see with the warning.The above dynamic import cannot be analyzed by vite.See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.
FYI
workStrdoes not work after build.For example, the code below would work instead.
const Component = lazy(() => import('@/App'));
I know what you mean.. when I need router config to render
const routerConfig = [
{
path: '/',
component: '@/App'
}
]
const Component = routerConfig.map(r => lazy(() => import(r.component))) // not work
what can I do?
I suppose this will work.
const routerConfig = [
{
path: '/',
component: () => import('@/App')
}
]
const Component = routerConfig.map(r => lazy(r.component))
I suppose this will work.
const routerConfig = [ { path: '/', component: () => import('@/App') } ] const Component = routerConfig.map(r => lazy(r.component))
is help me, thanks