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

codemod: ERR_REQUIRE_ESM when migrating from v4 to v5 #7154

Closed
wangwalton opened this issue Mar 21, 2024 · 5 comments
Closed

codemod: ERR_REQUIRE_ESM when migrating from v4 to v5 #7154

wangwalton opened this issue Mar 21, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@wangwalton
Copy link

Describe the bug

ERR_REQUIRE_ESM when migrating from v4 to v5 with codegen

Your minimal, reproducible example

NA

Steps to reproduce

Running this

 npx jscodeshift@latest ./src/ \                                                                                                                                                                                      main *
  --extensions=ts,tsx \
  --parser=tsx \
  --transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.js

gives this error:

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/dev/node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.js from /Users/.npm/_npx/a3dac9416cb5dcf1/node_modules/jscodeshift/src/Worker.js not supported.
remove-overloads.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename remove-overloads.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/./node_modules/@tanstack/react-query/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Object.newLoader [as .js] (/Users//.npm/_npx/a3dac9416cb5dcf1/node_modules/pirates/lib/index.js:121:7)
    at setup (./_npx/a3dac9416cb5dcf1/node_modules/jscodeshift/src/Worker.js:93:18)
    at Object.<anonymous> (./_npx/a3dac9416cb5dcf1/node_modules/jscodeshift/src/Worker.js:45:3) {
  code: 'ERR_REQUIRE_ESM'
}

Expected behavior

No error

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

macos

Tanstack Query adapter

None

TanStack Query version

5.28.6

TypeScript version

No response

Additional context

No response

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 22, 2024

this is the same as :

if you know how to fix it, please contribute.

@TkDodo TkDodo added the help wanted Extra attention is needed label Mar 22, 2024
@TkDodo TkDodo changed the title ERR_REQUIRE_ESM when migrating from v4 to v5 with codegen codemod: ERR_REQUIRE_ESM when migrating from v4 to v5 Mar 22, 2024
ontanj added a commit to ontanj/tanstack-query that referenced this issue Apr 24, 2024
Rename CommonJS files in codemods to distinguish them from ES module
files otherwise used in this project.
Resolve an issue occuring since package.json in codemods is removed when
publishing causing module type data to be lost.

Fix issue TanStack#7154
lachlancollins added a commit that referenced this issue Apr 25, 2024
* bug(codemods): rename CommonJS files to .cjs

Rename CommonJS files in codemods to distinguish them from ES module
files otherwise used in this project.
Resolve an issue occuring since package.json in codemods is removed when
publishing causing module type data to be lost.

Fix issue #7154

* Fix knip errors

* Add file extension to tests

* Update migration doc

---------

Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com>
@lachlancollins
Copy link
Member

Fixed in #7333

@Pierre-Do
Copy link

Thanks for the fix! Would you mind releasing a version that includes it? Cheers!

@TkDodo
Copy link
Collaborator

TkDodo commented Apr 30, 2024

it should've been in 5.32.1

not sure why that hasn't been released... checking ...

@Pierre-Do
Copy link

Thanks @TkDodo , very much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants