我正试图从webpack迁移到vite。
以下是相关文件:
vite.config.ts
import { defineConfig } from 'vite'
import { VitePluginNode } from 'vite-plugin-node'
import babel from 'vite-plugin-babel';
import commonjs from 'vite-plugin-commonjs'
export default defineConfig({
server: {
port: 3001,
},
build: {
target: 'esnext',
commonjsOptions: { transformMixedEsModules: true }
},
plugins: [
commonjs(),
babel(),
...VitePluginNode({
adapter: 'express',
appPath: 'some/path/server',
exportName: 'app',
tsCompiler: 'esbuild',
}),
],
})
tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs", // have also tried "esnext"
"lib": ["es7", "es2015", "es2017", "dom", "esnext"],
"moduleResolution": "node", // have also tried "bundler"
"esModuleInterop": true,
}
}
运行开发服务器时,我得到:
[vite] (ssr) Error when evaluating SSR module some/path/server:
|- ReferenceError: exports is not defined
at eval (/path/to/some/file/some-file.js:5:23)
它抱怨的相关文件实际上只是:
export * from 'isomorphicSecrets'
任何帮助都将不胜感激。