-
Hi there. I'm in the process of upgrading a large rails app from 6 to 7. In Rails 6 we were using Webpacker and have decided to use vite to manage javascript in the new version. In development using
My application.js looks like the following:
and my vite.config.ts has the following settings:
When I change the require line for select2 like so:
It will compile, but select2 does not work on the page when I visit it in the browser; instead I get the console error to say
I guess this means it isn't loaded. I can't quite see how to resolve this. Does anyone have any tips? I expect I'm missing some config from my vite.config.ts but I'm at a bit of a loss. Thanks for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Gareth! It's likely that If it works in development, and you are using Vite 3, perhaps you should try using esbuild when building, with: build: {
// Avoid using @rollup/plugin-commonjs
commonjsOptions: {
include: [],
},
},
// Use esbuild at build time.
optimizeDeps: {
disabled: false,
}, This is the default behavior in Vite 4. |
Beta Was this translation helpful? Give feedback.
Hi Gareth!
It's likely that
select2
is packaged in a way that confuses Rollup or Esbuild, and doesn't work as expected in ESM.If it works in development, and you are using Vite 3, perhaps you should try using esbuild when building, with:
This is the default behavior in Vite 4.