generated from Tahul/vue-composable-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Failed to serve on production: Uncaught ReferenceError: require is not defined #20
Labels
Comments
johnson86tw
changed the title
Failed to serve static files: Uncaught ReferenceError: require is not defined
Failed to serve on production: Uncaught ReferenceError: require is not defined
Nov 19, 2021
The solution of this issue is using // vite.config.ts
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { defineConfig } from 'vite'
import WindiCSS from 'vite-plugin-windicss'
import inject from '@rollup/plugin-inject'
export default defineConfig({
root: 'demo/',
plugins: [vue(), WindiCSS()],
resolve: {
alias: {
'vue-dapp': resolve(__dirname, './src/index.ts'),
},
},
build: {
rollupOptions: {
plugins: [inject({ Buffer: ['buffer', 'Buffer'] })],
},
commonjsOptions: {
transformMixedEsModules: true,
},
},
}) It comes from following two discussions: |
This was referenced Mar 3, 2022
New solution implemented in PR #98 and vue3-dapp-starter |
7 tasks
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because Vite is only for ES module, I used resolve.alias to solve the problem that Vite can't import the built-in node.js package from the third-party modules. Most of the effort is to resolve @walletconnect/web3-provider. There're lots of node.js built-in packages being used.
See these lines:
But in this scenario, when I build the demo files and run
yarn serve:demo
, it failed to run the app and give me:require is not defined
.This is hard to resolve. I don't know why
yarn dev
works but it failed on production.Reference
The text was updated successfully, but these errors were encountered: