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: __DEFINES__ is not defined #19

Closed
enigmazack opened this issue Aug 22, 2021 · 7 comments
Closed

Uncaught ReferenceError: __DEFINES__ is not defined #19

enigmazack opened this issue Aug 22, 2021 · 7 comments

Comments

@enigmazack
Copy link

I just clone the template and run 'pnpm i' and 'pnpm dev', and load the extension to chrome, but I get this error

Uncaught ReferenceError: __DEFINES__ is not defined

for the backgound script. This error introduced from this file
https://github.com/vitejs/vite/blob/fa30f76e49de0ca8abd96c1fd866da0512ed29b9/packages/vite/src/client/env.ts
I try to use yarn and firefox, same error.

@wensonsmith
Copy link
Contributor

back to vite 2.4.3 works

@enigmazack
Copy link
Author

2.4.3

Worked, a lot thanks

@eladcandroid
Copy link

eladcandroid commented Aug 24, 2021

I'm still facing it, even with Vite 2.5.1

image

image

@tmkx
Copy link
Collaborator

tmkx commented Aug 25, 2021

It's because that the background script imports /@vite/client since this PR, and then Vite will pre-bundle the deps, but, pre-bundling will not replace magic constants such as __DEFINES__.

You can try this workaround:

 optimizeDeps: {
   include: ['vue', '@vueuse/core'],
-   exclude: ['vue-demi'],
+   exclude: ['vue-demi', '@vite/client', '@vite/env'],
 },

and then delete Vite's cache dir node_modules/.vite

This will be solved in vitejs/vite#4716

@antfu antfu closed this as completed in d4507b2 Aug 25, 2021
@iceshu
Copy link

iceshu commented Jul 31, 2022

I have the some issue with vite v2.9.14
image
the dev env is ok but the product build is not work.
image

@zypy333
Copy link

zypy333 commented Apr 3, 2023

I met the same problem in another project. I reinstall a different verion of nodejs may cause the problem.I guess the cache does not match the nodejs I used
I solved the problem by deleting the node_modules and the package-lock.json and rebuild the program

@jessfeliciano
Copy link

Just wanted to contribute a bit here since I ran into the same issue and was able to finally figure it out. It turns out that it was because I had this in my index.html: <script type="module" src="/@vite/client"></script>

I had initially updated my vite config file with this solution from above:

` optimizeDeps: {
include: ['vue', '@vueuse/core'],

  • exclude: ['vue-demi'],
  • exclude: ['vue-demi', '@vite/client', '@vite/env'],
    },`

But this didn't make a difference for me for whatever reason. I decided to instead simply delete the script tag and I was able to get it all to work.

The clue for me was this post: vitejs/vite#12344 (comment)

I realized that having <script type="module" src="/@vite/client"></script> in index.html was somehow causing this script tag to be recognized: <script type="module" src="./src/main.jsx"></script>

I don't fully understand why, but I hope this is helpful for anyone else.

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

7 participants