So I'm using vite for my project which is a monorepo setup using turborepo. There are no problems while using dev mode or building the project, however when I serve the project I'm getting the error Uncaught (in promise) TypeError: n2.BigInt is not a function
. Can someone please help why the dev mode and build mode work differently for vite?
Putting my config below
export default defineConfig({
plugins: [
react(),
viteTsconfigPaths(),
svgrPlugin(),
legacy(),
commonjs(),
nodePolyfills({ protocolImports: true }),
],
optimizeDeps: {
esbuildOptions: {
target: "es2020", // Enable Big integer literals
define: {
global: "globalThis",
},
supported: {
bigint: true,
},
},
},
resolve: {
alias: {
assert: "assert",
buffer: "buffer",
crypto: "crypto-browserify",
http: "stream-http",
https: "https-browserify",
os: "os-browserify/browser",
process: "process/browser",
stream: "stream-browserify",
util: "util",
"~@fontsource": "@fontsource",
},
},
server: {
open: true,
port: 3000,
},
build: {
minify: false,
target: "es2020", // Enable Big integer literals
commonjsOptions: {
transformMixedEsModules: true, // Enable @walletconnect/web3-provider which has some code in CommonJS
},
rollupOptions: {
// maxParallelFileOps: 2,
cache: false,
},
outDir: "build",
},
});
I tried changing the vite config with different settings for rollup and esbuildoptions but nothing worked
The latest issues are caused by a Uniswap package dependancy, you need to polyfill JSBI
answer here Vite app works in DEV but not after BUILD and PREVIEW BigInt is not a function