web-infra-dev / modern.js

Modern.js is a web engineering system, including a web framework and a npm package solution.
https://modernjs.dev/en/
MIT License
4.26k stars 351 forks source link

[Bug]: ReferenceError: process is not defined #5836

Closed yf-yang closed 2 weeks ago

yf-yang commented 3 weeks ago

Version

System:
    OS: macOS 13.2.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 28.32 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Browsers:
    Chrome: 125.0.6422.176
    Safari: 16.3
  npmPackages:
    @modern-js/app-tools: ^2.53.0 => 2.53.0 
    @modern-js/module-tools: ^2.53.0 => 2.53.0 
    @modern-js/plugin-tailwindcss: 2.53.0 => 2.53.0

Details

Idk what's wrong here.

It complains when checking process.env.IS_REACT18.

If modern.config.js set disableNodePolyfill=false, then the error goes away, but process.env.IS_REACT18 is still not correctly set.

Reproduce link

https://github.com/yf-yang/modernjs-monorepo-example/tree/ts-bundler-bug

Reproduce Steps

cd apps/app
pnpm dev

Then open the browser.

yf-yang commented 2 weeks ago

The cause: In a pnpm workspace, I install @modern-js/app-tools at the root folder. Therefore, its internal appDirectory is resolved the root folder. Then modernjs tries to read its package.json to find the react version. If I execute the command in a workspace folder which installs React 18, then it could not be correctly resolved. Add @modern.js/app-tools as dependency of workspace folder can fix the issue.