Skip to content

got ERR_REQUIRE_ESM on implicit-children #62

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

Closed
marwen-cherif opened this issue May 18, 2022 · 4 comments · Fixed by #63
Closed

got ERR_REQUIRE_ESM on implicit-children #62

marwen-cherif opened this issue May 18, 2022 · 4 comments · Fixed by #63
Assignees
Labels
bug Something isn't working

Comments

@marwen-cherif
Copy link

Hi,
I've got a "ERR_REQUIRE_ESM" error, trying to run implicit-children codemod

Output:

C:\Users\dorki\WebstormProjects\reversio-front>npx types-react-codemod implicit-children .\packages/@savgroup-front-common/ui/src/atoms/AddAndRemove/AddAndRemove.tsx --dry
executing "C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules.bin\jscodeshift --extensions=tsx,ts "--ignore-pattern=/node_modules/" --transform C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\types-react-codemod\transforms\implicit-children.js --dry .\packages/@savgroup-front-common/ui/src/atoms/AddAndRemove/AddAndRemove.tsx"
Processing 1 files...
Spawning 1 workers...
Running in dry mode, no files will be written!
Sending 1 files to free worker...
Browserslist: caniuse-lite is outdated. Please run the following command: yarn upgrade
C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\types-react-codemod\transforms\implicit-children.js:141
undefined
^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\dorki\WebstormProjects\reversio-front\node_modules\babel-preset-react-app\node_modules@babel\runtime\helpers\esm\toConsumableArray.js from C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\types-react-codemod\transforms\implicit-children.js not supported.
Instead change the require of toConsumableArray.js in C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\types-react-codemod\transforms\implicit-children.js to a dynamic import() which is available in all CommonJS modules.
at Object.newLoader [as .js] (C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\pirates\lib\index.js:141:7)
at Object. (C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\types-react-codemod\transforms\implicit-children.js:10:50)
at Module._compile (C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\pirates\lib\index.js:136:24)
at Object.newLoader [as .js] (C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\pirates\lib\index.js:141:7)
at setup (C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\jscodeshift\src\Worker.js:91:18)
at Object. (C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\jscodeshift\src\Worker.js:45:3) {
code: 'ERR_REQUIRE_ESM'
}

Node.js v18.2.0
All done.
Results:
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 5.345seconds

@eps1lon
Copy link
Owner

eps1lon commented May 18, 2022

Does it work with node 16?

@marwen-cherif
Copy link
Author

marwen-cherif commented May 19, 2022

Ah Thank you, it works on node 16
node 14 : KO
node 16 : OK
node 18 : KO

@eps1lon
Copy link
Owner

eps1lon commented May 19, 2022

I want to investigate this though. Tests are currently running on 14.x, 16.x, 17.x and 18.x so I'm missing something in the testing setup

@eps1lon
Copy link
Owner

eps1lon commented May 21, 2022

What's odd to me is why it would require C:\Users\dorki\WebstormProjects\reversio-front\node_modules\babel-preset-react-app\node_modules@babel\runtime\helpers\esm\toConsumableArray.js from C:\Users\dorki\AppData\Local\npm-cache_npx\07333c78fb78394f\node_modules\types-react-codemod\transforms\implicit-children.js

It reaches into your local node_modules from the global node_modules. That shouldn't be happening. So I'm probably not declaring some dependency correctly.

Edit: But then why is it importing some babel-runtime function from my transforms? Is codeshift transpiling the transforms? The published file does not contain any reference to toConsumeableArray: https://unpkg.com/browse/[email protected]/transforms/implicit-children.js

Edit2: I think I need to tell jscodeshift to not transform the transforms: facebook/jscodeshift#395 (comment). So the bug report actually revealed a potential optimization 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants