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] Module not found: Error: Package path ./helpers/esm/regeneratorRuntime is not exported from package \@ant-design\pro-list\node_modules\@babel\runtime (see exports field in \node_modules\@ant-design\pro-list\node_modules\@babel\runtime\package.json) #5273

Closed
stantoxt opened this issue May 22, 2022 · 11 comments · Fixed by #5281 or #5314

Comments

@stantoxt
Copy link

stantoxt commented May 22, 2022

🐛 bug 描述

当引入 @ant-design/pro-list ,编译报错
Module not found: Error: Package path ./helpers/esm/regeneratorRuntime is not exported from package @ant-design\pro-list\node_modules@babel\runtime (see exports field in \node_modules@ant-design\pro-list\node_modules@babel\runtime\package.json)

查看对应目录下的@babel\runtime\package.json 确实里面没有 regeneratorRuntime
但是 node_modules@babel\runtime\package.json 下面有 regeneratorRuntime

不知道是什么原因?和这个有关系吗?

babel/babel#14538

dvajs/dva#2493

📷 复现步骤

🏞 期望结果

💻 复现代码

@github-actions
Copy link

github-actions bot commented May 22, 2022

以下的 Issues 可能会帮助到你 / The following issues may help you

@nicolo-ribaudo
Copy link

Hi! Babel maintainer here. This error looks different from the linked dva issue; I'll take a look later today.

@stantoxt
Copy link
Author

stantoxt commented May 22, 2022

@nicolo-ribaudo I copied manually root node_modules/@babel/runtime folder to all ant-design-procomponents node_modules and it successfully compiled. Maybe this is not a bug, but I don't know why, I cant find any issue about, if this is about the network problem.

@stantoxt
Copy link
Author

My project worked fine,before yarn add ant-design/pro-list.According to the error, there is no config about regeneratorRuntime in node_modules@ant-design\pro-list\node_modules@babel\runtime\package.json. I want to know the problem

@nicolo-ribaudo
Copy link

Ok so, here is the problem:

  • This repository is built using father

  • To generate optimal output, Babel needs to know which version of @babel/runtime you (in this case, @ant-design/pro-list) want to use. Why? For example, @babel/runtime/helpers/esm/regeberatorRuntime has been introduced in Babel 7.18.0, so Babel will inject an import to it only if "whoever called Babel" (father-build, in this case) told "Hey Babel, you can safely assume that I'm using @babel/runtime@^7.18.0".

  • father-build uses require("@babel/runtime/package.json").version to detect the version: https://github.com/umijs/father/blob/master/packages/father-build/src/getBabelConfig.ts

  • @and-design/pro-list depends on @babel/runtime@^7.16.3:

    "@babel/runtime": "^7.16.3",

  • I believe that, when they published the last version of @and-design/pro-components, the maintainers of this package had @babel/[email protected] in their node_modules and thus father assumed that ^7.18.0 was safe: for this reason, Babel injected that import/require to @babel/runtime/helpers/esm/regeneratorRuntime which was introduced in 7.18.0.

  • I believe that your @ant-design/pro-list/node_modules/@babel/runtime is an older version, between 7.16.3 and 7.17.9 and thus @babel/runtime/helpers/esm/regeneratorRuntime does not exist.

How can this problem be fixed? (Note: these are 3 different solutions, sorted from the most ugly one to the best one)

  1. You can make sure that @ant-design/pro-list/node_modules/@babel/runtime is at least 7.18.0. The safest way to do it is to add @babel/runtime@^7.18.0 as a dependency of your project, run yarn and then yarn dedupe (or npx yarn-deduplicate if you are using Yarn 1).
  2. The maintainers of @and-design/pro-list can update their package.json to explicitly depend on 7.18.0 and not ^7.16.3. Also, I suggest using ~ instead of ^ to specify its version to avoid automatic minor updates, so that father won't accidentally tell Babel that it's safe to use a new version containing new helpers.
  3. The maintainers of father should improve their @babel/runtime version detection logic:
    • Instead of using require("@babel/runtime/package.json").version, they could resolve the app/library's package.json file and read the version from require("/path/to/app/or/library/package.json").dependencies["@babel/runtime"].
    • They could provide an option in .fatherrc.js to specify which @babel/runtime version you want to target.

@stantoxt
Copy link
Author

stantoxt commented May 22, 2022

@nicolo-ribaudo Thank you so much. That's cool. I have spent time understanding this and benefit a lot from your detailed explanation.

  • I believe that your @ant-design/pro-list/node_modules/@babel/runtime is an older version, between 7.16.3 and 7.17.9 and thus @babel/runtime/helpers/esm/regeneratorRuntime does not exist.
    I tested it and the version is 7.17.9.
  1. You can make sure that @ant-design/pro-list/node_modules/@babel/runtime is at least 7.18.0. The safest way to do it is to add @babel/runtime@^7.18.0 as a dependency of your project, run yarn and then yarn dedupe (or npx yarn-deduplicate if you are using Yarn 1).

yarn dedupe is deprecated, I used yarn install --flat,but the choice answers are too many to choose it cause much time to choose the answers. I deleted node_modules and use command yarn install --flat --ignore-engines --ignore-platform , but this cause some library package compatibility problem, i would test it again.

  • The maintainers of @and-design/pro-list can update their package.json to explicitly depend on 7.18.0 and not ^7.16.3. Also, I suggest using ~ instead of ^ to specify its version to avoid automatic minor updates, so that father won't accidentally tell Babel that it's safe to use a new version containing new helpers.

  • The maintainers of father should improve their @babel/runtime version detection logic:

    • Instead of using require("@babel/runtime/package.json").version, they could resolve the app/library's package.json file and read the version from require("/path/to/app/or/library/package.json").dependencies["@babel/runtime"].
    • They could provide an option in .fatherrc.js to specify which @babel/runtime version you want to target.

I think the two other solutions should be the key to this problem.

At the end, @nicolo-ribaudo thanks again.

@stantoxt stantoxt reopened this May 22, 2022
@nicolo-ribaudo
Copy link

yarn dedupe is deprecated, I used yarn install --flat,but the choice answers are too many to choose it cause much time to choose the answers.

You could also try to manually delete every @babel/runtime from your lockfile and then run yarn install, it might successfully install only the latest version.

@stantoxt
Copy link
Author

stantoxt commented May 22, 2022

yarn dedupe is deprecated, I used yarn install --flat,but the choice answers are too many to choose it cause much time to choose the answers.

You could also try to manually delete every @babel/runtime from your lockfile and then run yarn install, it might successfully install only the latest version.

let me have a try

@stantoxt
Copy link
Author

@billyrrr if other pro components need to be updated to the latest @babel/runtime version, like pro-list,pro-field,pro-form.

@billyrrr
Copy link
Contributor

@stantoxt Other pro components definitely also need an update. I am unfamiliar with the error caused by these modules. I did not attempt a fix.

billyrrr pushed a commit to billyrrr/pro-components that referenced this issue May 30, 2022
billyrrr pushed a commit to billyrrr/pro-components that referenced this issue May 30, 2022
chenshuai2144 pushed a commit that referenced this issue May 30, 2022
@ozkary
Copy link

ozkary commented Oct 4, 2022

Yes, adding the @babel/runtime@^7.18.0 to the React project with Antd solved this error in my case. This error came out after upgrading to React@v18 and [email protected]

Package path ./helpers/esm/regeneratorRuntime is not exported from package \@ant-design\pro-list\node_modules\@babel\runtime

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