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.41k stars 367 forks source link

[Bug]: monorepo root dependency react version not right #6224

Closed tky753 closed 3 weeks ago

tky753 commented 3 weeks ago

Version

System:
    OS: Windows 11 10.0.22631
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 14.52 GB / 31.95 GB
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @modern-js/app-tools: 2.59.0 => 2.59.0
    @modern-js/tsconfig: 2.59.0 => 2.59.0

Details

my monorepo structure looks like:

- apps
   - app1
       - modern.config.ts
       - package.json
   - app2
       - modern.config.ts
       - package.json
- package.json

root package.json has dependencies like:

"dependencies": {
    "@modern-js/runtime": "2.59.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
},
"devDependencies": {
    "@modern-js/app-tools": "2.59.0",
    "@modern-js/tsconfig": "2.59.0",
    "typescript": "~5.0.4"
}

apps/app1 and app2 inherits dependencies from root

when I run modern dev in foder /apps/app1, the browser shows warning: Warning: ReactDOM.render is no longer supported in React 18. image

it's because react is an inherited dependency, so the runtimePlugin can't get its version correctly.

Reproduce link

https://github.com/tky753/modern-js-monorepo-bug-report

Reproduce Steps

pnpm i
cd apps/app1
pnpm dev
zllkjc commented 3 weeks ago

Thanks for the feedback~. Currently, Modern.js requires defining React versions, and we recommend managing versions in sub-projects.

zllkjc commented 3 weeks ago

We do not plan to support this behavior for now