T
TanStack10mo ago
stormy-gold

ERR_REQUIRE_ESM when running pnpm build for Vite + React project

I just migrated from code-based to file-based routing.
at Module.<anonymous> (/Users/me/Desktop/project/Frontend/node_modules/.pnpm/@tanstack+router-generator@1.86.0/node_modules/@tanstack/router-generator/dist/cjs/filesystem/virtual/getRouteNodes.cjs:3:1) { code: 'ERR_REQUIRE_ESM'
16 Replies
deep-jade
deep-jade10mo ago
please provide a minimal complete example , e.g. by forking one of the existing examples on stackblitz
stormy-gold
stormy-goldOP10mo ago
Oh it seems like its because my build script was this
"build": "tsr generate && tsc && vite build",
"build": "tsr generate && tsc && vite build",
Removing tsr generate fixes this issue
deep-jade
deep-jade10mo ago
it should still work with tsr
stormy-gold
stormy-goldOP10mo ago
Seems like it does not - will see if i can reproduce
xenial-black
xenial-black10mo ago
I am also getting this issue with the tsr generate command. I am running all the latest @tanstack packages:
"dependencies": {
"@tanstack/react-router": "^1.87.2",
"@tanstack/react-store": "^0.6.1"
},
"devDependencies": {
"@tanstack/eslint-plugin-router": "^1.85.3",
"@tanstack/router-cli": "^1.86.0",
"@tanstack/router-generator": "^1.86.0",
"@tanstack/router-plugin": "^1.86.0",
"@tanstack/router-devtools": "^1.87.1",
}
"dependencies": {
"@tanstack/react-router": "^1.87.2",
"@tanstack/react-store": "^0.6.1"
},
"devDependencies": {
"@tanstack/eslint-plugin-router": "^1.85.3",
"@tanstack/router-cli": "^1.86.0",
"@tanstack/router-generator": "^1.86.0",
"@tanstack/router-plugin": "^1.86.0",
"@tanstack/router-devtools": "^1.87.1",
}
Full error is:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/beefchimi/Development/Personal/earwurm-react-demo/node_modules/tsx/dist/esm/index.mjs not supported.
Instead change the require of /Users/beefchimi/Development/Personal/earwurm-react-demo/node_modules/tsx/dist/esm/index.mjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Module.<anonymous> (/Users/beefchimi/Development/Personal/earwurm-react-demo/node_modules/@tanstack/router-generator/dist/cjs/filesystem/virtual/getRouteNodes.cjs:3:1) {
code: 'ERR_REQUIRE_ESM'
}
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/beefchimi/Development/Personal/earwurm-react-demo/node_modules/tsx/dist/esm/index.mjs not supported.
Instead change the require of /Users/beefchimi/Development/Personal/earwurm-react-demo/node_modules/tsx/dist/esm/index.mjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Module.<anonymous> (/Users/beefchimi/Development/Personal/earwurm-react-demo/node_modules/@tanstack/router-generator/dist/cjs/filesystem/virtual/getRouteNodes.cjs:3:1) {
code: 'ERR_REQUIRE_ESM'
}
deep-jade
deep-jade10mo ago
can you share a reproducer?
xenial-black
xenial-black10mo ago
This is the project I've just started that I am running into this issue with: https://github.com/beefchimi/earwurm-react-demo Sorry, it isn't as minimal of a reproduction as you may want, but it should still hopefully be helpful.
GitHub
GitHub - beefchimi/earwurm-react-demo: Exploration of using Earwurm...
Exploration of using Earwurm in React. Contribute to beefchimi/earwurm-react-demo development by creating an account on GitHub.
deep-jade
deep-jade10mo ago
do you even use virtual file routes?
xenial-black
xenial-black10mo ago
nope There are no imports from virtual-file-routes or calls to rootRoute. only calls to createRootRoute I think I finally got that command to run by downgrading all of the tanstack dependencies... not sure exactly what the last working version is though. I'm generally in the 1.85.0 range
deep-jade
deep-jade10mo ago
if you can narrow it down it makes it easier for me to spot the issue
xenial-black
xenial-black10mo ago
Here is exactly what I downgraded that led to a working router generation: https://github.com/beefchimi/earwurm-react-demo/commit/f01ebce7ff61cc7d22b001d4708bc248eaa40342 I can say that the @tanstack/router-generator package is definitely required in order for this to have worked... where as I believe the @tanstack/react-router documentation doesn't state that this is a requirement. Neither these pages requires you to install the router-generator: - https://tanstack.com/router/latest/docs/framework/react/installation - https://tanstack.com/router/latest/docs/framework/react/quick-start I can bring back the error by either: - Removing the router-generator package and reinstalling my node modules, or - Bumping router-generator to ^1.86.0
deep-jade
deep-jade10mo ago
ok will look into this later can you point me to a commit that fails to build? ah wait I can reproduce this fails with npm but works with pnpm with npm I get the following file in node_modules/.bin/tsr:
#!/usr/bin/env node

require('../dist/cjs/index.cjs')
#!/usr/bin/env node

require('../dist/cjs/index.cjs')
whereas with pnpm:
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -z "$NODE_PATH" ]; then
export NODE_PATH="/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/bin/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/node_modules"
else
export NODE_PATH="/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/bin/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/node_modules:$NODE_PATH"
fi
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../@tanstack/router-cli/bin/tsr.cjs" "$@"
else
exec node "$basedir/../@tanstack/router-cli/bin/tsr.cjs" "$@"
fi
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -z "$NODE_PATH" ]; then
export NODE_PATH="/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/bin/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/node_modules"
else
export NODE_PATH="/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/bin/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/router-cli/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules/@tanstack/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/@tanstack+router-cli@1.86.0/node_modules:/private/tmp/earwurm-react-demo/node_modules/.pnpm/node_modules:$NODE_PATH"
fi
if [ -x "$basedir/node" ]; then
exec "$basedir/node" "$basedir/../@tanstack/router-cli/bin/tsr.cjs" "$@"
else
exec node "$basedir/../@tanstack/router-cli/bin/tsr.cjs" "$@"
fi
can you please create a github issue for this?
xenial-black
xenial-black10mo ago
Yep, one minute
xenial-black
xenial-black10mo ago
GitHub
[Generator] Failure to generate routes with NPM · Issue #2968 · Tan...
Which project does this relate to? Router Describe the bug See Discord discussion for more context: https://discord.com/channels/719702312431386674/1023930177224462388 It appears that something shi...
xenial-black
xenial-black10mo ago
@Manuel Schiller thank you for fixing this!
correct-apricot
correct-apricot10mo ago
I'll check it out once it's out. Had this behaviour with pnpm + RsPack + Nx.

Did you find this page helpful?