79326470

Date: 2025-01-03 12:36:44
Score: 0.5
Natty:
Report link

I was able to fix this error by ensuring that no instances of react/jsx-runtime were imported or bundled into the transpiled code.

The issue was that the main.js file (inside the dist folder) contained react/jsx-runtime, which caused duplicate React export objects since the development environment was also using React.

I updated the rollupOptions inside vite.config.ts to properly exclude the react/jsx-runtime code:

export default defineConfig({
  { ... }
  build: {
    copyPublicDir: false,
    lib: {
      entry: resolve(__dirname, './lib/main.ts'),
      formats: ['es'],
    },
    rollupOptions: {
      external: ['react', 'react/jsx-runtime'],
      output: {
        assetFileNames: 'assets/[name][extname]',
        entryFileNames: '[name].js',
      },
    },
  },
});
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Supermacka