question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setting `global` in `vite.define` breaks build

See original GitHub issue

Environment


  • Operating System: Darwin
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.2
  • Package Manager: yarn@3.1.1
  • Builder: vite
  • User Config: ssr, runtimeConfig, typescript, css, buildModules, alias
  • Runtime Modules: -
  • Build Modules: @vueuse/nuxt@8.4.2, @intlify/nuxt3@0.1.10

Reproduction

Simply set these settings, and execute npx nuxi generate or nuxi build.

// nuxt.config.ts
export default defineConfig({
  // ...
  alias: {
    // ...
    './runtimeConfig': './runtimeConfig.browser',
  },
  vite: {
    // ...
    define: {
      "global": {},
    }
  }
});

Describe the bug

More precisely, it seems that the global variable conflicts with nuxt’s middleware or something similar. However, this error does not appear when running nuxi dev.

Additional context

This global parameter is the currently standard flag that is added to solve runtime issues with AWS Amplify. See #2308 for the related discussion.

Logs

------------------------------
67:   nuxtApp._activeRoute = reactive(activeRoute);
68:   nuxtApp._middleware = nuxtApp._middleware || {
69:     global: [],
        ^
70:     named: {}
71:   };


 ERROR  Unexpected token (Note that you need plugins to import files that are not JavaScript)   

 ------------------------------

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
rvmourikcommented, May 10, 2022

In that case the issue to follow is #1922 linked above by @pi0.

Thanks @danielroe, is this an issue that is a high priority? It’s open for about a half year, I am not complaining whatsoever, just interested if it is something that can be fixed easily or that it is difficult to fix.

Thanks 😃

2reactions
rvmourikcommented, May 17, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Building for Production - Vite
When it is time to deploy your app for production, simply run the vite build command. By default, it uses <root>/index.html as the...
Read more >
API - esbuild
#Define. Supported by: Transform | Build. This feature provides a way to replace global identifiers with constant expressions. It can be a way...
Read more >
defining global variables with vite development - Stack Overflow
define is a config that tells Vite how to perform a search-and-replace. It can only replace one string for another (objects cannot be...
Read more >
Docs • Svelte
SvelteKit utilizes Vite to build your code and handle server-side rendering (SSR). ... <script> export let person; // this will only set `name`...
Read more >
Adding Vite to Your Existing Web App | CSS-Tricks
We also create the following vite.config.ts right next to the index.html file in the project directory. import { defineConfig } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found