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 issueDescribe 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.
Reproduction
build with 2.9.6
https://stackblitz.com/edit/vitejs-vite-pnbcp8?file=package.json
build with 3.1.x
https://stackblitz.com/edit/vitejs-vite-ecer22?file=package.json

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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Comments:8 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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: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