You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot use the router plugin in commonjs webpack config #3186
This is the error that happens. chalk v5 does not provide support for commonjs. Since the router plugin package do provide commonjs exports I think this is a bug that should be fixed here.
[webpack-cli] Failed to load 'webpack.config.js' config
[webpack-cli] Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@tanstack/router-plugin/node_modules/chalk/source/index.js from node_modules/@tanstack/router-plugin/dist/cjs/logger.cjs not supported.
I had to pin both router and vite plugin like this to make it work (I guess I could play with even newer versions, but I was too lazy and these simply worked)
This is the error that shows up, if you are trying to use newer versions.
An error occurred while processing files for the @nx/vite/plugin plugin.
- xxx/vite.config.ts: require() of ES Module xxx/node_modules/@tanstack/router-plugin/node_modules/chalk/source/index.js from xxx/node_modules/@tanstack/router-plugin/dist/cjs/logger.cjs not supported.
Instead change the require of index.js in xxx/node_modules/@tanstack/router-plugin/dist/cjs/logger.cjs to a dynamic import() which is available in all CommonJS modules.
Error [ERR_REQUIRE_ESM]: require() of ES Module xxx/node_modules/@tanstack/router-plugin/node_modules/chalk/source/index.js from xxx/node_modules/@tanstack/router-plugin/dist/cjs/logger.cjs not supported.
Instead change the require of index.js in xxx/node_modules/@tanstack/router-plugin/dist/cjs/logger.cjs to a dynamic import() which is available in all CommonJS modules.
The simplest solution would be to downgrade chalk to 4.x 🤔
Activity
schiller-manuel commentedon Jan 26, 2025
what would be a solution? replace chalk by a library that has both cjs and ESM?
paypal-edveriksson commentedon Jan 27, 2025
I did a workaround by pinning chalk to v4 for now.
velein commentedon Jan 29, 2025
It is the same with
Viteplugin.I had to pin both router and vite plugin like this to make it work (I guess I could play with even newer versions, but I was too lazy and these simply worked)
This is the error that shows up, if you are trying to use newer versions.
The simplest solution would be to downgrade chalk to 4.x 🤔
fix: replace chalk by ansis for CJS compat
schiller-manuel commentedon Jan 31, 2025
fixed in https://github.com/TanStack/router/releases/tag/v1.98.5
paypal-edveriksson commentedon Jan 31, 2025
Thank you, I can confirm that it fixed the issue!