Need help with some dependencies #6282
-
Hi! I'm trying to migrate from CRA to Vite, but I'm a bit stucked with some external dependencies. One of them is shpjs: https://github.com/calvinmetcalf/shapefile-js. When I run vite dev, I get I have tried some rollup plugins but I haven't solved it. Could someone give me some ideas? I'm thinking on forking the library and remove all node dependencies to transpile it to a ES module, but I guess that there is some kind of combination of plugin + configuration that I don't know that solves this kind of problems Sample repo is here: https://github.com/qatium/vite-react-ts-app Thank you all! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
We fixed it. We'll share how we make it work:
|
Beta Was this translation helpful? Give feedback.
-
I have encountered the same problem as you,and here are my solution: |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for creating this discussion, but neither of the solutions provided were helpful for me, so, this is how I solved the problem: import { nodePolyfills } from 'vite-plugin-node-polyfills';
export default defineConfig({
plugins: [..., nodePolyfills()],
server: { port: 3000 },
...
}); Just That's it. This solution worked for Vite 5.1.4. |
Beta Was this translation helpful? Give feedback.
We fixed it. We'll share how we make it work:
TypeError: Buffer2 is undefined
we had to create an alias invite.config.js
like this: ` Buffer: "buffer". Then we installed a library called "buffer" and we imported the module wherever we needed it. This way we made sure we were using a buffer that works in the browser.rbush2 is not defined
. It was related to one of our dependencies called @turf/line-split, as rbush was a dependency of this one. The cause of the error was that Vite wasn't compiling therequire()
inside of that library, because we're using ESM. So, we had to install a plugin called@originjs/vite-plugin-commonjs
and target that dependency.