Uncaught ReferenceError: global is not defined
metahubwallet opened this issue · 3 comments
metahubwallet commented
vue: 3.3.4
vite: 4.4.9
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { setAutoImport } from './settings/plugins/autoImport';
import { setAutoComponents } from './settings/plugins/components';
export default defineConfig({
plugins: [
vue(),
nodePolyfills({
include: ['buffer', 'process'],
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true,
},
protocolImports: false,
}),
setAutoImport(),
setAutoComponents(),
viteCompression(), // { disable: !isProduction }
],
...
});
davidmyersdev commented
Hey there, @metahubwallet. I appreciate the config, but can you please add a reproducible example on either StackBlitz or CodeSandbox? Thanks!
paulbse commented
`<script>
if (global === undefined) {
var global = window;
}
</script>`<script>
if (global === undefined) {
var global = window;
}
</script>`
Just add this to your index.html file in your src folder
davidmyersdev commented
@paulbse the example you provided would expectedly error since .html
files are not processed by these plugins. If you instead put the script in a .js
or .ts
file and imported it, it would likely work as expected.