issue with polyfill in `vite build` output
See original GitHub issueDescribe the bug
during my exploration with @toruslabs/openlogin sdk, i find out that using vite.js gives a different result between dev and build environment.
both vite & vite build running successfully. the only problem started when we browse the app via browser.
my value of vite.config.js
export default defineConfig({
publicDir: 'static',
plugins: [vue()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
optimizeDeps: {
include: [
],
exclude: [
],
esbuildOptions: {
sourcemap: false,
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true
}),
],
}
},
build:{
exclude: [
],
assetsDir: 'src',
sourcemap: false,
define: {
global: 'globalThis',
},
rollupOptions: {
output: {
globals: {
},
},
plugins: [
rollupNodePolyFill(),
],
},
commonjsOptions: {
transformMixedEsModules: true,
},
},
})
development env
production env
yarn build or vite build
serve -d dist
- browse the output via browser, got error:
index.7152b104.js:2 TypeError: Cannot read properties of undefined (reading 'call') at new _r (index.7152b104.js:12:34847) at new P2 (index.7152b104.js:13:48810) at new m0 (index.7152b104.js:13:56954) at z2.setupStream (index.7152b104.js:13:60950) at z2.init (index.7152b104.js:13:60850) at async Promise.all (:3000/index 0) at async Y2.init (index.7152b104.js:19:5045) at async Proxy.login (index.7152b104.js:19:12134)
Reproduction
https://github.com/akangaziz/vite-openlogin-issue
System Info
` System:
OS: macOS 11.4
CPU: (8) arm64 Apple M1
Memory: 117.55 MB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.0 - /usr/local/bin/node
Yarn: 1.22.10 - /opt/homebrew/bin/yarn
npm: 8.5.4 - /opt/homebrew/bin/npm
Browsers:
Chrome: 99.0.4844.74
Firefox: 97.0.2
Safari: 14.1.1
npmPackages:
@vitejs/plugin-vue: ^2.2.2 => 2.2.4
vite: ^2.8.4 => 2.8.6 `
Used Package Manager
yarn
Logs
both `vite` or `vite build` runs successfully.
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:16 (5 by maintainers)
Top GitHub Comments
Can we get some guidance on how to solve this in Vite? It seems a common problem and not being able to use node package because Vite doesn’t support polyfills makes continuing with Vite problematic.
From what I can see, the problem with the process package is that when polyfilling, files in vite/.deps (i’m guessing this is some kind of caching mechanism to speed up live loading) is creating a conflicting process function. So, it seems this is a problem within Vite?
It would be great to at least get clarity on this as the only “workaround” seems very clunky.
Node polyfilling isn’t something Vite supports by default as it often brings a larger client bundle size. It looks like this is a configuration issue with polyfills than a bug in Vite. Closing this for now.