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.

vite cannot recognize "process" in 2.9.15 and 3.1.x in runtime & the output is different from 2.9.6

See original GitHub issue

Describe the bug

Vite cannot recognize “process” in 2.9.15 and 3.1.x when compile. And the bundle volume will grow larger, but it works well in 2.9.6.

image

Reproduction

build with 2.9.6

https://stackblitz.com/edit/vitejs-vite-pnbcp8?file=package.json image

build with 3.1.x

https://stackblitz.com/edit/vitejs-vite-ecer22?file=package.json

image

amazing

The same code’s different output is amazing!

Steps to reproduce

1、yarn 2、yarn build 3、search in the file lib/scms-common-resource.umd.js with keyword “process”

System Info

System:
    OS: macOS 11.5.1
    CPU: (8) x64 Apple M1
    Memory: 38.30 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 14.18.2 - ~/work/emsdk/node/14.18.2_64bit/bin/node
    Yarn: 1.22.15 - ~/.yarn/bin/yarn
    npm: 6.14.15 - ~/work/emsdk/node/14.18.2_64bit/bin/npm

Used Package Manager

yarn

Logs

No response

Validations

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
sapphi-redcommented, Oct 14, 2022

This is a breaking change in Vite 3. https://vitejs.dev/guide/migration.html#advanced:~:text=process.env.* is now preserved in library mode

You’ll need to change define to:

const define = {
  'process.env.NODE_ENV': JSON.stringify('production'),
  __PRODUCTION__: PRODUCTION,
};
1reaction
LeeeeeeMcommented, Oct 13, 2022

@LeeeeeeM please provide a reproduction that shows Vite failing on compile.

vite 3.1.x compiles well, but the output is different from 2.9.6.

reproduction: https://stackblitz.com/edit/vitejs-vite-ecer22?file=lib%2Fscms-common-resource.umd.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting
Syntax Error / Type Error happens​​ This is because Vite uses ESM and it is always strict mode inside ESM. For example, you...
Read more >
Yarn 3.1, Vite 2.9, cannot find package vite
If I set yarn to 3.1.1, I get a different error related to pnp.cjs . On the other hand, setting yarn to the...
Read more >
vite
1, /// <reference types="node" />. 2. 3, import { BuildOptions as BuildOptions_2 } from 'esbuild';. 4, import { ChangeEvent } from 'rollup';.
Read more >
Configuring Vitest
If you want to have a different configuration for testing or your main app doesn't rely on Vite specifically, you could either:.
Read more >
Vite Plugin Federation: Module Federation for Vite & Rollup
import federation from '@originjs/vite-plugin-federation' export default { input: 'src/index.js', output: { format: 'esm', dir: 'dist' }, plugins: ...
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