exports is not defined
See original GitHub issueDescribe the bug
enable transformMixedEsModules
and run yarn build && yarn preview
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import inject from '@rollup/plugin-inject'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@page': resolve(__dirname, 'src/page'),
'@img': resolve(__dirname, 'src/assets/img'),
stream: 'stream-browserify',
process: 'process/browser',
zlib: 'browserify-zlib',
util: 'util',
},
},
base: './',
server: {
port: 3000,
},
define: {
'process.env.BASE_URL': '"/"',
},
build: {
commonjsOptions: {
transformMixedEsModules: true,
exclude: ['node_modules/naive-ui/**'],
},
rollupOptions: {
// @ts-ignore
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString()
}
},
},
},
},
})
package.json
{
"name": "vite-project",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "vite build",
"dev": "vite --host",
"i18n:report": "vue-cli-service i18n:report --src \"./src/**/*.?(js|vue)\" --locales \"./src/locales/**/*.json\"",
"preview": "vite preview "
},
"dependencies": {
"@types/node": "^17.0.19",
"ethers": "^5.5.4",
"ipfs-http-client": "^56.0.1",
"naive-ui": "^2.25.3",
"vfonts": "^0.0.3",
"vue": "^3.2.25",
"vue-dapp": "^0.4.7",
"vue-i18n": "9",
"vue-router": "4"
},
"devDependencies": {
"@intlify/vue-i18n-loader": "^3.0.0",
"@originjs/vite-plugin-commonjs": "^1.0.3",
"@rollup/plugin-inject": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@vitejs/plugin-vue": "^2.2.0",
"@vue/cli-shared-utils": "^5.0.1",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"eslint": "^8.9.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.4.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-vue": "^8.5.0",
"prettier": "^2.5.1",
"process": "^0.11.10",
"typescript": "^4.5.4",
"util": "^0.12.4",
"vite": "^2.8.5",
"vue-cli-plugin-i18n": "~2.3.1",
"vue-tsc": "^0.29.8"
},
"packageManager": "yarn@1.22.17"
}
main.ts
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import i18n from './i18n'
import { VueDapp } from 'vue-dapp'
createApp(App)
.use(i18n)
.use(router)
.use(VueDapp, {
infuraId: '31c7d0c9966a4fa9963c5276a39e0b1a',
appName: 'castable-nft',
})
.mount('#app')
Reproduction
https://github.com/MetaplasiaTeam/castable-nft-web
System Info
$ npx envinfo --system --npmPackages '{vite,@vitejs/*}' --binaries --browsers
Need to install the following packages:
envinfo
Ok to proceed? (y) y
System:
OS: macOS 12.2
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Memory: 1.40 GB / 16.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.14.0 - /usr/local/opt/node@16/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.3.1 - /usr/local/opt/node@16/bin/npm
Browsers:
Chrome: 98.0.4758.109
Firefox: 97.0.1
Safari: 15.3
npmPackages:
@vitejs/plugin-vue: ^2.2.0 => 2.2.4
vite: ^2.8.5 => 2.8.5
Used Package Manager
yarn
Logs
view build
$ yarn build --debug
yarn run v1.22.17
warning ../package.json: No license field
$ vite build --debug
vite:config bundled config file loaded in 57.09ms +0ms
vite:config using resolved config: {
vite:config plugins: [
vite:config 'alias',
vite:config 'vite:modulepreload-polyfill',
vite:config 'vite:resolve',
vite:config 'vite:html-inline-proxy',
vite:config 'vite:css',
vite:config 'vite:esbuild',
vite:config 'vite:json',
vite:config 'vite:wasm',
vite:config 'vite:worker',
vite:config 'vite:worker-import-meta-url',
vite:config 'vite:asset',
vite:config 'vite:vue',
vite:config 'vite:define',
vite:config 'vite:css-post',
vite:config 'vite:watch-package-data',
vite:config 'vite:build-html',
vite:config 'commonjs',
vite:config 'vite:data-uri',
vite:config 'rollup-plugin-dynamic-import-variables',
vite:config 'vite:asset-import-meta-url',
vite:config 'inject',
vite:config 'vite:build-import-analysis',
vite:config 'vite:esbuild-transpile',
vite:config 'vite:terser',
vite:config 'vite:reporter',
vite:config 'vite:load-fallback'
vite:config ],
vite:config resolve: {
vite:config dedupe: undefined,
vite:config alias: [
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object], [Object],
vite:config [Object]
vite:config ]
vite:config },
vite:config base: './',
vite:config server: {
vite:config preTransformRequests: true,
vite:config port: 3000,
vite:config fs: { strict: true, allow: [Array], deny: [Array] }
vite:config },
vite:config define: {
vite:config 'process.env.BASE_URL': '"/"',
vite:config __VUE_OPTIONS_API__: true,
vite:config __VUE_PROD_DEVTOOLS__: false
vite:config },
vite:config build: {
vite:config target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config polyfillModulePreload: true,
vite:config outDir: 'dist',
vite:config assetsDir: 'assets',
vite:config assetsInlineLimit: 4096,
vite:config cssCodeSplit: true,
vite:config cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ],
vite:config sourcemap: false,
vite:config rollupOptions: { plugins: [Array], output: [Object] },
vite:config minify: 'esbuild',
vite:config terserOptions: {},
vite:config write: true,
vite:config emptyOutDir: null,
vite:config manifest: false,
vite:config lib: false,
vite:config ssr: false,
vite:config ssrManifest: false,
vite:config reportCompressedSize: true,
vite:config chunkSizeWarningLimit: 500,
vite:config watch: null,
vite:config commonjsOptions: {
vite:config include: [Array],
vite:config extensions: [Array],
vite:config transformMixedEsModules: true,
vite:config exclude: [Array]
vite:config },
vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] }
vite:config },
vite:config ssr: { external: [ 'vue', '@vue/server-renderer' ] },
vite:config configFile: '/Users/nihaocun/Code/caseable-nft-web/vite.config.ts',
vite:config configFileDependencies: [ 'vite.config.ts' ],
vite:config inlineConfig: {
vite:config root: undefined,
vite:config base: undefined,
vite:config mode: undefined,
vite:config configFile: undefined,
vite:config logLevel: undefined,
vite:config clearScreen: undefined,
vite:config build: {}
vite:config },
vite:config root: '/Users/nihaocun/Code/caseable-nft-web',
vite:config publicDir: '/Users/nihaocun/Code/caseable-nft-web/public',
vite:config cacheDir: '/Users/nihaocun/Code/caseable-nft-web/node_modules/.vite',
vite:config command: 'build',
vite:config mode: 'production',
vite:config isProduction: true,
vite:config preview: {
vite:config port: undefined,
vite:config strictPort: undefined,
vite:config host: undefined,
vite:config https: undefined,
vite:config open: undefined,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config env: { BASE_URL: './', MODE: 'production', DEV: false, PROD: true },
vite:config assetsInclude: [Function: assetsInclude],
vite:config logger: {
vite:config hasWarned: false,
vite:config info: [Function: info],
vite:config warn: [Function: warn],
vite:config warnOnce: [Function: warnOnce],
vite:config error: [Function: error],
vite:config clearScreen: [Function: clearScreen],
vite:config hasErrorLogged: [Function: hasErrorLogged]
vite:config },
vite:config packageCache: Map(0) { set: [Function (anonymous)] },
vite:config createResolver: [Function: createResolver],
vite:config optimizeDeps: {
vite:config esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined }
vite:config },
vite:config worker: {
vite:config format: 'iife',
vite:config plugins: [
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object], [Object], [Object],
vite:config [Object]
vite:config ],
vite:config rollupOptions: {}
vite:config }
vite:config } +9ms
vite v2.8.5 building for production...
transforming (3505) node_modules/lodash/isObjectLike.jsUse of eval is strongly discouraged, as it poses security risks and may cause issues with minification
Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification
✓ 3554 modules transformed.
Generated an empty chunk: "aes-js"
Generated an empty chunk: "async-validator"
Generated an empty chunk: "date-fns-tz"
Generated an empty chunk: "scrypt-js"
Generated an empty chunk: "vue"
dist/assets/web-logo.c22cd076.png 14.38 KiB
dist/index.html 8.03 KiB
dist/assets/index.77d7d899.js 15.09 KiB / gzip: 5.56 KiB
dist/assets/@css-render.b1caa279.js 1.78 KiB / gzip: 0.76 KiB
dist/assets/@emotion.6322e2ae.js 0.55 KiB / gzip: 0.26 KiB
dist/assets/@metamask.3fa410c8.js 1.55 KiB / gzip: 0.78 KiB
dist/assets/@intlify.8a89ecad.js 26.34 KiB / gzip: 9.09 KiB
dist/assets/aes-js.2c08e1e6.js 0.00 KiB / gzip: 0.02 KiB
dist/assets/async.daf7e711.js 7.93 KiB / gzip: 2.25 KiB
dist/assets/async-validator.66a9c2c1.js 0.00 KiB / gzip: 0.02 KiB
dist/assets/async-mutex.1f8468ec.js 11.31 KiB / gzip: 4.10 KiB
dist/assets/available-typed-arrays.b025928e.js 0.37 KiB / gzip: 0.25 KiB
dist/assets/bech32.0161db04.js 2.22 KiB / gzip: 1.04 KiB
dist/assets/base64-js.642fef99.js 1.41 KiB / gzip: 0.74 KiB
dist/assets/bind-decorator.6f02a152.js 0.47 KiB / gzip: 0.30 KiB
dist/assets/brorand.89f8d4d7.js 0.90 KiB / gzip: 0.38 KiB
dist/assets/call-bind.407e0841.js 0.78 KiB / gzip: 0.45 KiB
dist/assets/cipher-base.32f5a0c8.js 1.51 KiB / gzip: 0.61 KiB
dist/assets/buffer.b2a88918.js 24.86 KiB / gzip: 7.19 KiB
dist/assets/bn.js.387b47fa.js 42.37 KiB / gzip: 11.06 KiB
dist/assets/clsx.8fd3e01d.js 0.48 KiB / gzip: 0.32 KiB
dist/assets/cookiejar.5d57a72c.js 3.35 KiB / gzip: 1.32 KiB
dist/assets/copy-to-clipboard.91f73d5f.js 1.76 KiB / gzip: 0.85 KiB
dist/assets/create-hash.d666fbd8.js 0.52 KiB / gzip: 0.32 KiB
dist/assets/date-fns-tz.bf5a877d.js 0.00 KiB / gzip: 0.02 KiB
dist/assets/css-render.fd7350c4.js 4.04 KiB / gzip: 1.77 KiB
dist/assets/detect-browser.ed3deee4.js 3.81 KiB / gzip: 1.55 KiB
dist/assets/decode-uri-component.4cf187fa.js 0.88 KiB / gzip: 0.50 KiB
dist/assets/date-fns.ecfd739c.js 7.10 KiB / gzip: 2.39 KiB
dist/assets/dijkstrajs.bd6915f6.js 1.14 KiB / gzip: 0.58 KiB
dist/assets/eth-block-tracker.d1aeb0ab.js 3.48 KiB / gzip: 1.23 KiB
dist/assets/es-abstract.14c0589b.js 0.16 KiB / gzip: 0.16 KiB
dist/assets/eth-json-rpc-middleware.79197ff6.js 3.89 KiB / gzip: 1.43 KiB
dist/assets/eth-sig-util.f32d9f39.js 1.89 KiB / gzip: 0.83 KiB
dist/assets/eth-query.5602d7fb.js 2.96 KiB / gzip: 0.85 KiB
dist/assets/ethereum-common.6fed5496.js 4.46 KiB / gzip: 1.94 KiB
dist/assets/ethereum-cryptography.f1d51b76.js 2.83 KiB / gzip: 1.27 KiB
dist/assets/eth-json-rpc-filters.b423e7b2.js 21.04 KiB / gzip: 6.99 KiB
dist/assets/elliptic.25ea8d42.js 42.98 KiB / gzip: 13.37 KiB
dist/assets/ethereumjs-tx.8087008f.js 2.99 KiB / gzip: 1.15 KiB
dist/assets/ethjs-util.c63cb277.js 2.18 KiB / gzip: 0.94 KiB
dist/assets/evtd.5b1ed12a.js 3.67 KiB / gzip: 1.45 KiB
dist/assets/eventemitter3.dc5195d7.js 2.73 KiB / gzip: 1.03 KiB
dist/assets/ethereumjs-util.0f6a236f.js 14.11 KiB / gzip: 4.52 KiB
dist/assets/foreach.ca0366f9.js 0.30 KiB / gzip: 0.22 KiB
dist/assets/events.6cd1b6ce.js 5.94 KiB / gzip: 2.03 KiB
dist/assets/fast-safe-stringify.cbdf62a8.js 2.33 KiB / gzip: 0.88 KiB
dist/assets/has.c1051c46.js 0.13 KiB / gzip: 0.13 KiB
dist/assets/function-bind.cb3858f2.js 0.71 KiB / gzip: 0.40 KiB
dist/assets/ethereumjs-abi.be673097.js 25.26 KiB / gzip: 7.52 KiB
dist/assets/has-tostringtag.0722ba29.js 0.11 KiB / gzip: 0.12 KiB
dist/assets/has-symbols.668da340.js 0.97 KiB / gzip: 0.40 KiB
dist/assets/hash-base.d86a6bea.js 1.51 KiB / gzip: 0.67 KiB
dist/assets/get-intrinsic.d7b36144.js 7.60 KiB / gzip: 2.35 KiB
dist/assets/inherits.44344a27.js 0.33 KiB / gzip: 0.20 KiB
dist/assets/hmac-drbg.ea110cf4.js 1.83 KiB / gzip: 0.73 KiB
dist/assets/ieee754.1945c636.js 0.97 KiB / gzip: 0.57 KiB
dist/assets/is-generator-function.adf285e2.js 0.48 KiB / gzip: 0.30 KiB
dist/assets/is-arguments.8a6d59b2.js 0.47 KiB / gzip: 0.30 KiB
dist/assets/is-hex-prefixed.fef52274.js 0.21 KiB / gzip: 0.18 KiB
dist/assets/is-typedarray.90714367.js 0.62 KiB / gzip: 0.24 KiB
dist/assets/is-typed-array.79000807.js 0.95 KiB / gzip: 0.55 KiB
dist/assets/json-rpc-random-id.51bc6534.js 0.18 KiB / gzip: 0.17 KiB
dist/assets/hash.js.c5ec00a3.js 15.67 KiB / gzip: 5.87 KiB
dist/assets/js-sha256.47b9b189.js 10.25 KiB / gzip: 3.67 KiB
dist/assets/json-rpc-engine.d9a2bb27.js 0.34 KiB / gzip: 0.23 KiB
dist/assets/json-stable-stringify.9f61f119.js 1.31 KiB / gzip: 0.72 KiB
dist/assets/js-sha3.a94d76b6.js 9.84 KiB / gzip: 3.85 KiB
dist/assets/jsonify.6cba919e.js 3.25 KiB / gzip: 1.47 KiB
dist/assets/keccak.08972096.js 6.90 KiB / gzip: 2.62 KiB
dist/assets/minimalistic-assert.2f00d150.js 0.17 KiB / gzip: 0.14 KiB
dist/assets/md5.js.6b63375b.js 3.24 KiB / gzip: 1.26 KiB
dist/assets/lodash.749641a3.js 3.94 KiB / gzip: 1.74 KiB
dist/assets/minimalistic-crypto-utils.c60e18fc.js 0.62 KiB / gzip: 0.39 KiB
dist/assets/pify.8425b695.js 0.95 KiB / gzip: 0.48 KiB
dist/assets/process.a117d01b.js 1.67 KiB / gzip: 0.71 KiB
dist/assets/lodash-es.be71650d.js 19.75 KiB / gzip: 7.39 KiB
dist/assets/preact.5eba0374.js 12.54 KiB / gzip: 4.98 KiB
dist/assets/query-string.a8750f20.js 4.05 KiB / gzip: 1.55 KiB
dist/assets/randombytes.d5dcb359.js 0.64 KiB / gzip: 0.43 KiB
dist/assets/resize-observer-polyfill.8deb1e21.js 7.64 KiB / gzip: 2.49 KiB
dist/assets/ripemd160.98fa499d.js 2.77 KiB / gzip: 1.15 KiB
dist/assets/safe-buffer.b3a2c81a.js 0.91 KiB / gzip: 0.42 KiB
dist/assets/safe-event-emitter.75c7fb00.js 0.89 KiB / gzip: 0.53 KiB
dist/assets/readable-stream.2f3c69c5.js 37.27 KiB / gzip: 11.13 KiB
dist/assets/scrypt-js.a5252268.js 0.00 KiB / gzip: 0.02 KiB
dist/assets/semaphore.74132e4e.js 0.99 KiB / gzip: 0.48 KiB
dist/assets/rlp.9ce406e9.js 44.38 KiB / gzip: 11.67 KiB
dist/assets/secp256k1.c9423c09.js 10.66 KiB / gzip: 3.22 KiB
dist/assets/stream-browserify.9e4504c6.js 1.12 KiB / gzip: 0.54 KiB
dist/assets/split-on-first.3754ef4a.js 0.23 KiB / gzip: 0.19 KiB
dist/assets/sha.js.139f12d5.js 11.04 KiB / gzip: 4.02 KiB
dist/assets/seemly.576622a5.js 2.91 KiB / gzip: 1.31 KiB
dist/assets/strict-uri-encode.725b5ed5.js 0.12 KiB / gzip: 0.13 KiB
dist/assets/toggle-selection.b84dd588.js 0.41 KiB / gzip: 0.29 KiB
dist/assets/string_decoder.98ccc898.js 2.28 KiB / gzip: 0.81 KiB
dist/assets/typedarray-to-buffer.11fd1ba9.js 0.29 KiB / gzip: 0.21 KiB
dist/assets/strip-hex-prefix.3ff64792.js 0.13 KiB / gzip: 0.13 KiB
dist/assets/treemate.fbdf7cd8.js 6.98 KiB / gzip: 2.57 KiB
dist/assets/util-deprecate.2a270dee.js 0.42 KiB / gzip: 0.28 KiB
dist/assets/tslib.8453f610.js 1.11 KiB / gzip: 0.62 KiB
dist/assets/vooks.63397f1b.js 3.14 KiB / gzip: 1.34 KiB
dist/assets/vue.f8638657.js 0.00 KiB / gzip: 0.02 KiB
dist/assets/util.b282c1a7.js 11.84 KiB / gzip: 4.09 KiB
dist/assets/vdirs.03f40802.js 2.29 KiB / gzip: 0.82 KiB
dist/assets/vueuc.946fae02.js 15.73 KiB / gzip: 4.97 KiB
dist/assets/which-typed-array.2dd819c4.js 0.88 KiB / gzip: 0.50 KiB
dist/assets/vue-router.abd9a4a3.js 21.73 KiB / gzip: 8.89 KiB
dist/assets/xhr2-cookies.bb95a3ea.js 13.59 KiB / gzip: 3.98 KiB
dist/assets/vue-i18n.280ebf67.js 22.68 KiB / gzip: 7.35 KiB
dist/assets/web3-provider-engine.bb1974db.js 20.32 KiB / gzip: 5.68 KiB
dist/assets/xtend.45b7f156.js 0.18 KiB / gzip: 0.16 KiB
dist/assets/index.eafbc333.css 0.17 KiB / gzip: 0.15 KiB
dist/assets/index.0205f870.css 1.29 KiB / gzip: 0.53 KiB
dist/assets/index.750dbc8c.js 10.41 KiB / gzip: 2.84 KiB
dist/assets/@vue.9aef2748.js 60.76 KiB / gzip: 24.32 KiB
dist/assets/qrcode.a4c12404.js 48.60 KiB / gzip: 16.32 KiB
dist/assets/rxjs.724c13d0.js 108.20 KiB / gzip: 22.92 KiB
dist/assets/vue-dapp.452ba019.js 76.58 KiB / gzip: 21.42 KiB
dist/assets/@ethersproject.fc87f513.js 116.95 KiB / gzip: 36.34 KiB
dist/assets/@walletconnect.881ba526.js 132.61 KiB / gzip: 39.60 KiB
dist/assets/walletlink.741c166b.js 183.74 KiB / gzip: 49.20 KiB
dist/assets/naive-ui.82deb447.js 242.02 KiB / gzip: 65.46 KiB
✨ Done in 19.60s.
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
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Typescript ReferenceError: exports is not defined
I had the error "exports is not defined" coming from an imported NPM module. Changing my typescript config did nothing as I had...
Read more >ReferenceError: exports is not defined in TypeScript | bobbyhadz
To solve the "Uncaught ReferenceError: exports is not defined", add a script tag that defines an exports variable, e.g. <script>var exports = {};</script> ......
Read more >How to fix ReferenceError: exports is not defined TypeScript
Solution. If you are getting the error for code that runs in the browser, try defining a global exports variable above the script...
Read more >Uncaught ReferenceError: exports is not defined : r/typescript
Uncaught ReferenceError : exports is not defined · use module: "es6" in the tsconfig, so that the generated modules code runs natively in...
Read more >Uncaught ReferenceError: exports is not defined #71 - GitHub
trying to: import { zodResolver } from "@hookform/resolvers/zod"; gives me: Uncaught ReferenceError: exports is not defined at Module.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think it’s a
lodash-es
problem, which I’ve ruled outvite.config.ts
This way
lodash-es
will not have problems, but there is a new problemClosing per @Niputi comment. @EndureBlaze feel free to create a new issue against the latest version of Vite if you still see the issue. Thansk!