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

ReferenceError: global is not defined #171

Closed
StefSchenkelaars opened this issue Dec 1, 2021 · 3 comments
Closed

ReferenceError: global is not defined #171

StefSchenkelaars opened this issue Dec 1, 2021 · 3 comments

Comments

@StefSchenkelaars
Copy link

I was trying to get this plugin up and running in my own project but bumped into the following error ReferenceError: global is not defined. So then the exploration started: I've checked out this repo and tried to boot the example app and I got the same error.

It happens only when running the dev server, the production build goes just fine. Therefore, the end-to-end tests are not failing. I could "fix" it by changing the vite.config.ts content with:

import { defineConfig } from "vite";
import reactRefresh from "@vitejs/plugin-react-refresh";
import relay from "vite-plugin-relay";

export default defineConfig({
  define: {
    global: {
      global: 'globalThis'
    }
  },
  plugins: [reactRefresh(), relay],
});

but actually I have no idea why that works. I've noticed that something similar has been changed in #152 but I'm not too much into this to completely oversee the impact.

Full Stacktrace
RelayReferenceMarker.js:333 Uncaught ReferenceError: global is not defined
    at node_modules/relay-runtime/lib/store/RelayPublishQueue.js (RelayReferenceMarker.js:333)
    at __require2 (chunk-ENMAWK7U.js?v=1254bb04:36)
    at node_modules/relay-runtime/lib/store/RelayModernEnvironment.js (RelayModernStore.js:652)
    at __require2 (chunk-ENMAWK7U.js?v=1254bb04:36)
    at node_modules/relay-runtime/lib/index.js (index.js:10)
    at __require2 (chunk-ENMAWK7U.js?v=1254bb04:36)
    at node_modules/relay-runtime/index.js (index.js:10)
    at __require2 (chunk-ENMAWK7U.js?v=1254bb04:36)
    at node_modules/react-relay/lib/ReactRelayContext.js (ReactRelayContext.js:15)
    at __require2 (chunk-ENMAWK7U.js?v=1254bb04:36)
@oscartbeaumont
Copy link
Owner

Add something like the following to your index.html.

<script>let global = globalThis;</script>

The definition was recently removed from this Vite plugin as it was causing issues with some use cases and is also against Vite's recommendations for plugin authors. When removing it I tested the example project and found no issues so I must have done something incorrectly. I will fix the example and add some documentation about this to the README at some point in the next week.
Thanks for letting me know about this issue.

@StefSchenkelaars
Copy link
Author

Thanks for the quick reply. I've made a PR to update the tests setup to use the dev server by default: #172

@oscartbeaumont
Copy link
Owner

Documentation for this has been added to the README so I am going to close this issue.

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