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.

Uncaught ReferenceError: process is not defined

See original GitHub issue
  • [x ] Read the docs.
  • [x ] Use Vite >=2.0. (1.x is no longer supported)
  • [ x] If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

When I upgrade vite to any version after 2.0.0-beta.62 I get the error as follows: App.vue:36 Uncaught ReferenceError: process is not defined at setup (App.vue:36) at callWithErrorHandling (runtime-core.esm-bundler.js:154) at setupStatefulComponent (runtime-core.esm-bundler.js:6419) at setupComponent (runtime-core.esm-bundler.js:6380) at mountComponent (runtime-core.esm-bundler.js:4118) at processComponent (runtime-core.esm-bundler.js:4094) at patch (runtime-core.esm-bundler.js:3712) at render2 (runtime-core.esm-bundler.js:4794) at mount (runtime-core.esm-bundler.js:3019) at Object.app.mount (runtime-dom.esm-bundler.js:1220)

Reproduction

https://github.com/ljcremer/vite-test

System Info

  • vite version: 2.0.0-beta.67
  • Operating System: Windows 10
  • Node version:v12.19.1
  • Package manager (npm/yarn/pnpm) and version:6.14.8

Logs (Optional if provided reproduction)

  1. Run vite or vite build with the --debug flag.
  2. Provide the error log here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

28reactions
bergkvistcommented, Mar 1, 2021

I found that I can use the following in vite.config.ts to avoid “Uncaught ReferenceError: process is not defined”:

import { defineConfig } from 'vite'
// ...
export default defineConfig({
  // ...
  define: {
    'process.env': {}
  }
})

18reactions
antonio-wundermartcommented, Mar 5, 2021

Is there any way to support process.env way to access dotenv? The problem is that using import.meta goes in conflict with jest (we use typescript): https://github.com/kulshekhar/ts-jest/issues/1174 And there’s no viable way of using it for us without introducing babel and additional overhead.

The only other strategy is to give up on using Vite and roll back to vue cli, which is something that we are trying to avoid since we like Vite performances.

Is there any other way to set process.env?

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Uncaught ReferenceError: process is not defined
Node.js code must be run by the node process, not the browser (the code must run in the server). To run the code,...
Read more >
ReferenceError: “process is not defined” - GIMTEC
In this case, process is not defined in the browser environment, hence the error. The solution is to remove the reference to process...
Read more >
React ReferenceError: process is not defined | bobbyhadz
To solve the "Uncaught ReferenceError: process is not defined" in React, open your terminal in your project's root directory and update the version...
Read more >
"Uncaught ReferenceError: process is not defined" and the ...
The Uncaught ReferenceError: process is not defined happens when when a non-existent (here: process) variable is referenced .
Read more >
process is not defined (NOT react-error-overlay ... - GitHub
Using the optional chaining operator with process ( process?.env ) throws a ReferenceError stating that process is not defined. I originally ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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