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',
},
},
},
});