Skip to content
Source
Sign inSign up
TanStack/query

codemod: ERR_REQUIRE_ESM when migrating from v4 to v5 #7154

Send to my agent
Closedwangwalton(GitHub profile, opens in a new tab) opened this issue 5 comments

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

  1. this is the same as :

    if you know how to fix it, please contribute.

  2. TkDodo added labelshelp wanted

  3. TkDodo changed the title

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

  5. it should've been in 5.32.1

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

  6. Thanks @TkDodo , very much appreciated

Sign in to join this conversation.