顶级等待在构建中给出错误,但在开发中工作
Top level await gives error in build but works on dev
我的代码在 运行 npm run dev
时有效,但是当我构建它时出现此错误。根据文档,我需要在 tsconfig.json 中将目标设置为 ES2017 或更高版本,但我使用的是我认为兼容的 ESNEXT
错误
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["./src"]
}
因为我在问题中使用了 vite,vite.config.ts 是我应该编辑的而不是 tsconfig.json
这是解决方法
vite.config.ts
export default defineConfig({
build: {
minify: 'esbuild',
target: "esnext"
}
})
我的代码在 运行 npm run dev
时有效,但是当我构建它时出现此错误。根据文档,我需要在 tsconfig.json 中将目标设置为 ES2017 或更高版本,但我使用的是我认为兼容的 ESNEXT
错误
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["./src"]
}
因为我在问题中使用了 vite,vite.config.ts 是我应该编辑的而不是 tsconfig.json
这是解决方法 vite.config.ts
export default defineConfig({
build: {
minify: 'esbuild',
target: "esnext"
}
})