Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] yarn pnp 模式 运行异常 #12610

Open
cx-emerge opened this issue Jul 31, 2024 · 5 comments
Open

[Bug] yarn pnp 模式 运行异常 #12610

cx-emerge opened this issue Jul 31, 2024 · 5 comments
Assignees

Comments

@cx-emerge
Copy link

What happens?

yarn pnp 模式 运行异常

$ yarn run dev

> project@0.1.0 start:dev
> cross-env REACT_APP_ENV=dev MOCK=none UMI_ENV=dev max dev

fatal - Error: Cannot find module 'react-dom/package.json' from '/home/user_name/projects/project_name/react-ui'
    at Function.resolveSync [as sync] (/home/user_name/projects/project_name/react-ui/.yarn/cache/@umijs-utils-npm-4.3.10-f14a24b540-8e6927179a.zip/node_modules/@umijs/utils/compiled/resolve/index.js:1
:12304)
    at resolveProjectDep (/home/user_name/projects/project_name/react-ui/.yarn/cache/@umijs-preset-umi-npm-4.3.10-62e6cec27d-80034f61c1.zip/node_modules/@umijs/preset-umi/dist/utils/resolveProjectDep.j
s:31:28)
    at configPlugins_default (/home/user_name/projects/project_name/react-ui/.yarn/cache/@umijs-preset-umi-npm-4.3.10-62e6cec27d-80034f61c1.zip/node_modules/@umijs/preset-umi/dist/features/configPlugin
s/configPlugins.js:43:71)
    at Service.initPlugin (/home/user_name/projects/project_name/react-ui/.yarn/cache/@umijs-core-npm-4.3.10-013fe041f2-9b39960cc0.zip/node_modules/@umijs/core/dist/service/service.js:463:40)
    at Service.run (/home/user_name/projects/project_name/react-ui/.yarn/cache/@umijs-core-npm-4.3.10-013fe041f2-9b39960cc0.zip/node_modules/@umijs/core/dist/service/service.js:259:18)
    at async Service.run2 (/home/user_name/projects/project_name/react-ui/.yarn/cache/umi-npm-4.3.10-0fdd4c725d-1a8fdd353b.zip/node_modules/umi/dist/service/service.js:65:12)
    at async /home/user_name/projects/project_name/react-ui/.yarn/cache/umi-npm-4.3.10-0fdd4c725d-1a8fdd353b.zip/node_modules/umi/dist/cli/forkedDev.js:23:5 {
  code: 'MODULE_NOT_FOUND'
}
fatal - A complete log of this run can be found in:
fatal - /home/user_name/projects/project_name/react-ui/node_modules/.cache/logger/umi.log
fatal - Consider reporting a GitHub issue on https://github.com/umijs/umi/issues

Mini Showcase Repository(REQUIRED)

重现库地址,在 react-ui 目录下执行操作

How To Reproduce

  • 拉取重现库
  • 进入 react-ui 目录
  • 升级项目 yarn 版本 yarn set version stable
  • 安装依赖 yarn install
  • 修改 react-ui/config/config.ts 文件
    • presets: ['umi-presets-pro']presets: [require.resolve('umi-presets-pro')]
  • 运行项目 yarn run dev
  • 复现问题

Context

  • Umi Version: 4.3.10
  • Node Version: 20.16.0
  • Yarn Version: 4.3.1
  • Platform: wsl 2 ubuntu 22.04.4 LTS
@sorrycc
Copy link
Member

sorrycc commented Aug 1, 2024

为啥用 Yarn + Pnp?要不换 Pnpm?

@cx-emerge
Copy link
Author

为啥用 Yarn + Pnp?要不换 Pnpm?

主要是通过 pnp 模式 使用 zero-installs
pnpm主要是节约磁盘空间,都是链接,应该是不支持 zero-installs

@xXAvoraXx
Copy link

为啥用 Yarn + Pnp?要不换 Pnpm?

主要是通过 pnp 模式 使用 zero-installs pnpm主要是节约磁盘空间,都是链接,应该是不支持 zero-installs

您找到解決方案了嗎?

@cx-emerge
Copy link
Author

为啥用 Yarn + Pnp?要不换 Pnpm?

主要是通过 pnp 模式 使用 zero-installs pnpm主要是节约磁盘空间,都是链接,应该是不支持 zero-installs

您找到解決方案了嗎?

暂时还没有

@cx-emerge
Copy link
Author

为啥用 Yarn + Pnp?要不换 Pnpm?

主要是通过 pnp 模式 使用 zero-installs pnpm主要是节约磁盘空间,都是链接,应该是不支持 zero-installs

您找到解決方案了嗎?

框架里用了 resolve 包,这个包可能不支持 pnp
以下是不修改框架代码的临时方案

.yarnrc.yml 添加以下内容

packageExtensions:
  "@umijs/plugins@*":
    dependencies:
      "@umijs/utils": "*"
  "@umijs/openapi@*":
    dependencies:
      "@umijs/utils": "*"
      "tslib": "*"
  "@umijs/request-record@*":
    dependencies:
      "@umijs/utils": "*"
  "@ant-design/pro-provider@*":
    dependencies:
      "dayjs": "*"
  "@ant-design/pro-card@*":
    dependencies:
      "@ant-design/cssinjs": "*"
  "@ant-design/pro-table@*":
    dependencies:
      "@ant-design/cssinjs": "*"
  "@ant-design/pro-form@*":
    dependencies:
      "rc-field-form": "*"
  "@ant-design/pro-layout@*":
    dependencies:
      "@ant-design/cssinjs": "*"
  "@ant-design/pro-list@*":
    dependencies:
      "@ant-design/cssinjs": "*"
      "@ant-design/pro-provider": "*"

执行 yarn up

强制解压包

yarn unplug react
yarn unplug react-dom
yarn unplug antd

进入 node_modules 目录, 链接强制解压包的目录

ln -s ../.yarn/unplugged/antd-virtual-43c8614e1e/node_modules/antd
ln -s ../.yarn/unplugged/react-npm-18.3.1-af38f3c1ae/node_modules/react
ln -s ../.yarn/unplugged/react-dom-virtual-036b0cd58b/node_modules/react-dom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants