Open
Description
Describe the bug
问题描述:
使用react-swc模版创建的项目,vite build target调整为es2022以支持Top-Level Await特性,然后在模块中通过一下方式使用
import _ from 'lodash'
const useStore = {
getState: () => {
return {
count: 0,
}
},
}
console.log('loading lazyModule', _)
const module = await import('@/utils/lazyModule');
console.log('module value is :', module.default)
export default useStore
本地运行没有任何问题,但是build之后preview运行代码会在await这一行直接静默结束,network可以看到chunkfile已经被懒加载成功,但是await永远不会resolve也不会reject没有任何报错,在src/utils/lazyModule.ts
第一行打断点也不会执行。
这里有一个复现的代码库你可以拉取到本地测试: [email protected]:Duo-Huang/test-tla.git
代码是一个最小可复现的demo, 主要代码文件src/store/index.ts
, src/utils/lazyModule.ts
代码中有详细的操作过程和现象描述
Reproduction
https://github.com/Duo-Huang/test-tla
Steps to reproduce
- clone my demo code:
git clone [email protected]:Duo-Huang/test-tla.git
pnpm i
pnpm build
pnpm preview
- bug is reproduced
System Info
System:
OS: macOS 15.3.2
CPU: (10) arm64 Apple M1 Pro
Memory: 70.55 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.asdf/installs/nodejs/v22.14.0/bin/node
Yarn: 1.22.22 - ~/.asdf/installs/nodejs/v22.14.0/bin/yarn
npm: 10.9.2 - ~/.asdf/plugins/nodejs/shims/npm
pnpm: 10.4.1 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 134.0.6998.89
Safari: 18.3.1
npmPackages:
@vitejs/plugin-react-swc: ^3.8.0 => 3.8.0
vite: ^6.2.2 => 6.2.2
Used Package Manager
pnpm
Logs
你可以观察chrome console中的log, 显示异常的执行, 没有报错
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- 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 vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.