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

feat: disable babel register #112

Merged
merged 1 commit into from
Mar 30, 2020
Merged

feat: disable babel register #112

merged 1 commit into from
Mar 30, 2020

Conversation

vagusX
Copy link
Member

@vagusX vagusX commented Mar 25, 2020

jscodeshift 默认会在跑 transform script 时,启用 @babel/register 将 babel 编译开启,并且使用写死的 babel config,结果导致所有的 transform scripts 会被编译成 es5,从而出现 regeneratorRuntime 和 core-js 找不到的情况

以下用户遇到类似问题,

目前这个修复可以正常运行在 #59 (comment) 用户提供的复现 repo 上

@vagusX vagusX requested review from afc163 and zombieJ March 25, 2020 17:21
@afc163
Copy link
Member

afc163 commented Mar 26, 2020

其实根本原因就是用了用户自定义的 .babelrc

@zombieJ
Copy link
Member

zombieJ commented Mar 27, 2020

流弊,福尔摩斯呐

@vagusX
Copy link
Member Author

vagusX commented Mar 29, 2020

其实根本原因就是用了用户自定义的 .babelrc

@afc163 根本原因链路有点长,简单来说就是

babel.config.js 在 pwd 下面导致报错的原因:

准确调试得出结论,因为有复现 demo
jscodeshift 默认会使用 @babel/register,从而使得 node 环境将 transform scripts 编译成 es5,这里 @babel/register 依赖了 @babel/core, @babel/core 会 load pwd 底下的 babel.config.js 从而导致 @babel/register 运行时会报错,如果你在项目的再外面一层时,则不会出现这个情况,比如 antd4-codemod reproduction/src 是不会报错的

一系列 core-jsregeneratorRuntime 报错原因

这一点上目前还是推测,因为没有本地复现的项目
如上述,jscodeshift 默认会使用 @babel/register,而我们当前在 transforms 的 utils 里面使用了不少 esnext 特性,包括 async/await,由于被 babel/register 牵连进来编译,导致出现一系列 core-jsregeneratorRuntime 报错

@vagusX vagusX merged commit c020dad into master Mar 30, 2020
@delete-merged-branch delete-merged-branch bot deleted the feat/disable-babel-register branch March 30, 2020 05:35
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

Successfully merging this pull request may close these issues.

3 participants