-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught ReferenceError: require is not defined in ViteJS #240
Comments
I was able to make it work via passing export default defineConfig({
...
build: {
commonjsOptions: {
transformMixedEsModules: true
},
}
}) Background: https://stackoverflow.com/a/63099935/1574484 |
To make this solution more visible for people with the same error, I want to add that this is happening with Sveltekit and the Netlify-adapter. @dahei’s solution added to |
Another solution is to import the browser minified code instead of the regular export of the package when you're running this package in the browser :
|
Describe the bug
The package includes
require
that causes an exception in a browser bundle built by ViteJS. It happens because of these lines:https://github.com/squirrellyjs/squirrelly/blob/master/src/file-utils.ts#L1-L2
That file should be imported only in nodejs build, not a browser. At least, it should not be included in ESM format
The text was updated successfully, but these errors were encountered: