hozana / next-translate-routes

Flexible and translated routes for Next.js without custom server
MIT License
115 stars 31 forks source link

Fix "unhandledRejection ReferenceError: ROUTER_CONTEXT_PATH is not defined" error, update next to 14.0.4 #86

Closed ristomatti closed 9 months ago

ristomatti commented 9 months ago

On our code base the fix done on #84 did not work either, as @esonensson commented on the PR as well.

I debugged this for quite some time. No matter what I tried, I couldn't find any way to make ROUTER_CONTEXT_PATH available during runtime. Then it occurred to me to add transpilePackages: ['next-translate-routes'] in our next.config.js. This fixed the issue at least on our codebase, so I decided to create this PR.

TBH I still don't understand why exactly does this work. I wasn't able to reproduce the problem with the example project thought, only with our code base. I'd be curious to know your take on this @cvolant.

cvolant commented 9 months ago

@ristomatti, thank you very much ! I did not know about this transpilePackages option, and I think it is exactly what we need here. I struggled a lot with this, this is why there is 1.11.0-0 up to 1.11.0-3 versions. None of them work, but maybe with you PR all of them would work. Let's keep it as is, release 1.11.0-4, and check.

ristomatti commented 9 months ago

@cvolant Is it possible that 1.11.0-4 got released with the old built .js files?

$ grep next-translate-routes package.json 
    "next-translate-routes": "^1.11.0-4",

$ cd node_modules/next-translate-routes

$ grep -R transpilePackages src plugin
src/plugin/withTranslateRoutes.ts:    transpilePackages: hasOldRouterContextPath
src/plugin/withTranslateRoutes.ts:      ? nextConfig.transpilePackages
src/plugin/withTranslateRoutes.ts:      : [...(nextConfig.transpilePackages || []), 'next-translate-routes'],

While on my fork:

$ grep version package.json 
  "version": "1.11.0-4",

$ yarn build

$ grep -R transpilePackages src plugin
src/plugin/withTranslateRoutes.ts:    transpilePackages: hasOldRouterContextPath
src/plugin/withTranslateRoutes.ts:      ? nextConfig.transpilePackages
src/plugin/withTranslateRoutes.ts:      : [...(nextConfig.transpilePackages || []), 'next-translate-routes'],
plugin/withTranslateRoutes.js:    return __assign(__assign({}, nextConfig), { transpilePackages: hasOldRouterContextPath
plugin/withTranslateRoutes.js:            ? nextConfig.transpilePackages
plugin/withTranslateRoutes.js:            : __spreadArray(__spreadArray([], __read((nextConfig.transpilePackages || [])), false), ['next-translate-routes'], false), webpack: function (conf, context) {
ristomatti commented 9 months ago

I'm also getting this:

$ yarn prerelease
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by @typescript-eslint/typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.3.1 <4.5.0

YOUR TYPESCRIPT VERSION: 4.9.5

Please only submit bug reports when using the officially supported version.

=============

Oops! Something went wrong! :(

ESLint: 7.32.0

Error: ELOOP: too many symbolic links encountered, stat '/home/ristomatti/Projects/next-translate-routes/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example/symlink-used-by-example'
    at Object.statSync (node:fs:1676:25)
    at statSafeSync (/home/ristomatti/Projects/next-translate-routes/node_modules/eslint/lib/cli-engine/file-enumerator.js:122:19)
    at FileEnumerator._iterateFilesRecursive (/home/ristomatti/Projects/next-translate-routes/node_modules/eslint/lib/cli-engine/file-enumerator.js:436:55)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator._iterateFilesRecursive (/home/ristomatti/Projects/next-translate-routes/node_modules/eslint/lib/cli-engine/file-enumerator.js:492:33)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator._iterateFilesRecursive (/home/ristomatti/Projects/next-translate-routes/node_modules/eslint/lib/cli-engine/file-enumerator.js:492:33)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator._iterateFilesRecursive (/home/ristomatti/Projects/next-translate-routes/node_modules/eslint/lib/cli-engine/file-enumerator.js:492:33)
    at _iterateFilesRecursive.next (<anonymous>)

Edit: It seems to pass if I delete the symlink before running.

cvolant commented 9 months ago

Maybe. I was testing (and there was some issues) when I got interrupted. I will try again but I am not sure when...

ristomatti commented 9 months ago

You noticed some side effects of this change?

I just bumped into another issue during CI build with transpilePackages set in next.config.js as a temporary solution. Apparently we're also using translateUrl and createNtrData directly in our next-sitemap script. I haven't yet tried if it works with next-translate-routes with the change integrated.

ristomatti commented 8 months ago

@cvolant Have you had an opportunity time to check the if the release 1.11.0-4 includes changes from this PR?

cvolant commented 8 months ago

@ristomatti I am really sorry for taking so long! I often think that I must solve these issues, but I am absolutely snowed under (... some meters under). And I will be at least until march...

ristomatti commented 8 months ago

No sweat, I know the feeling. We'll need to find some workaround.

cvolant commented 6 months ago

I finally had some time to look at it again. It has been too long since this issue appeared, I had to fix it, so I dropped the support of old next versions (<13.5.0) to fix the issue. I tried not to (1.11.0-0, -1, -2, -3, -4), but did not succeed. I hope it won't be an issue for anybody.