Skip to content
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 (vite, SSR) #263

Open
yooouuri opened this issue Jan 13, 2023 · 4 comments
Open

Uncaught ReferenceError: require is not defined (vite, SSR) #263

yooouuri opened this issue Jan 13, 2023 · 4 comments

Comments

@yooouuri
Copy link

Happens in Vite SSR mode

image

"vite": "^4.0.4"

Im playing a little bit with vite.config.ts, but sadly no success

image

@yooouuri yooouuri changed the title Uncaught ReferenceError: require is not defined (vite) Uncaught ReferenceError: require is not defined (vite, SSR) Jan 13, 2023
@yooouuri
Copy link
Author

It is fixable to use an alias:

'vuex-persist': 'vuex-persist/dist/cjs/index.js'

But there should a decent solution

@nsano-rururu
Copy link

nsano-rururu commented Apr 1, 2023

  • In Vite you can't use require() so you need to replace it with import appropriately
  • When running the code with vite, I feel that it is necessary to change the method of reading environment variables from process.env to import.meta.env

@yooouuri
Copy link
Author

yooouuri commented Apr 2, 2023

  • In Vite you can't use require() so you need to replace it with import appropriately

  • When running the code with vite, I feel that it is necessary to change the method of reading environment variables from process.env to import.meta.env

The require happens in the plug-in

@nsano-rururu
Copy link

nsano-rururu commented Apr 2, 2023

Need fix for vuex-persist
https://github.com/championswimmer/vuex-persist/blob/master/src/index.ts#L57

      FlattedJSON = require('flatted')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants