Comments (13)
Having the same issue of empty NEXT_PUBLIC_ROUTES environment variable.
So I tried to manually set it in Vercel's interface and got this.
Then I tried to manually set it in next.config.js but using a fake, smaller one and it worked.
So it definitely appears that we've got a size limit issue.
The problem is that with route definitions, it can happen easily.
Any suggestion welcome!
from next-translate-routes.
In order to get the translations client side, the withTranslateRoutes plugin sets a public env var containing your routes tree. The next-translate-routes/link reads from this env var to translate the route.
You get the > next-translate-routes - No routes tree defined. next-translate-routes plugin is probably missing from next.config.js
error if this env var is not found.
Do you have any idea why this env var is not set on the Vercel Function?
from next-translate-routes.
I'm afraid passing the stringified json routes via the NEXT_PUBLIC_ROUTES
env is a dead end.
It probably has to be revamped so routes are loaded globally like next-translate does with i18nConfig.
from next-translate-routes.
Actually it would even make sense to inject the routes into a property of i18nConfig
and modify getRoutesTree()
so it makes use of it.
from next-translate-routes.
Very interesting.
You are probably right about the env var being a dead end...
The problem with config injection by an app hoc is that it should be imported from a file. If I understand correctly, next-translate uses this method to make user-made config available client side, but in next-translate-routes case, it is some computed data.
- We could try to edit the config file and add computed values...
- Or maybe something is possible with some webpack magic...
- Or, we could keep the env var trick and split the stringified values in as many env vars as needed, with a dynamic name, NEXT_PUBLIC_ROUTES_1, NEXT_PUBLIC_ROUTES_2, etc., then concat them back in getRoutesTree().
from next-translate-routes.
Unfortunately it's not 4KB per variable, it's 4KB in total!
Anyway, I had to find a quick and dirty workaround for the website I'm working on and here is what I did.
I forked your project and just changed getRouteTree() like this:
declare global {
var i18nConfig: any & { routesTree: TRouteBranch }
interface Window {
i18nConfig: Object & { routesTree: TRouteBranch };
}
}
export const getRoutesTree = () => {
if (typeof window === 'undefined') {
return global.i18nConfig?.routesTree || {}
}
return window.i18nConfig?.routesTree || {}
}
Now, in my project I have a command line script that generates a routesTree.json
file.
And routesTree
is injected into i18n.js
.
And it does the trick!
from next-translate-routes.
Unfortunately it's not 4KB per variable, it's 4KB in total!
Ok, so env var id definitely a dead end.
I think webpack DefinePlugin could do the job. I will try it, and if it does not, I will try something close to your solution.
from next-translate-routes.
@antoninbeaufort, @dperetti, @wangwailok, could you try with next-translate-routes@next and tell me if it works for you?
from next-translate-routes.
I was just trying it out, the first mistake is gone, but the second one remains:
2021-12-29T18:58:54.091Z 143f8f3a-631a-4859-8048-9251ab38b006 ERROR Error: ENOENT: no such file or directory, scandir '/var/task/public/locales/fr'
at Object.readdirSync (fs.js:1047:3)
at getLocaleNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:175:23)
at /var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:181:20
at Array.map (<anonymous>)
at getNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:180:44)
at createConfig (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:221:29)
at _callee$ (/var/task/node_modules/next-i18next/dist/commonjs/serverSideTranslations.js:199:53)
at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:294:22)
at Generator.next (/var/task/node_modules/regenerator-runtime/runtime.js:119:21) {
errno: -2,
syscall: 'scandir',
path: '/var/task/public/locales/fr',
page: '/mes-commandes'
}
RequestId: 143f8f3a-631a-4859-8048-9251ab38b006 Error: Runtime exited with error: exit status 1
Runtime.ExitError
But it looks like it's related to the next-i18next package now. (See i18next/next-i18next#1552)
from next-translate-routes.
error - ./pages/_app.tsx Error: [next-translate-routes] - No withTranslateRoutes high order component found in _app.
from next-translate-routes.
I was just trying it out, the first mistake is gone, but the second one remains:
2021-12-29T18:58:54.091Z 143f8f3a-631a-4859-8048-9251ab38b006 ERROR Error: ENOENT: no such file or directory, scandir '/var/task/public/locales/fr' at Object.readdirSync (fs.js:1047:3) at getLocaleNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:175:23) at /var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:181:20 at Array.map (<anonymous>) at getNamespaces (/var/task/node_modules/next-i18next/dist/commonjs/config/createConfig.js:180:44) at createConfig (/var/task/node_modules/next-i18next/dist/com [...] Error: Runtime exited with error: exit status 1 Runtime.ExitError
But it looks like it's related to the next-i18next package now. (See i18next/next-i18next#1552)
Yes, it comes from next-i18next. If you remove next-translate-routes, do you still have the error?
Did you see this one: i18next/next-i18next#1553
from next-translate-routes.
I was trying the 1.7.0-1
error - ./pages/_app.tsx Error: [next-translate-routes] - No withTranslateRoutes high order component found in _app.
Ops, I see. I will fix it soon. For now you can try importing 'next-translate-routes' with single quotes.
from next-translate-routes.
Yes, it comes from next-i18next. If you remove next-translate-routes, do you still have the error? Did you see this one: isaachinman/next-i18next#1553
I don't know because I didn't need it, I've just added localePath
in my next.config.js and it's fully working now.
Like this :
module.exports = {
i18n: {
defaultLocale: 'fr',
locales: ['fr', 'en'],
localePath: path.resolve('./public/locales')
},
};
from next-translate-routes.
Related Issues (20)
- Can't install the latest version v1.9.0 with yarn HOT 1
- Does this plugin support locale format en-US, es-MX, etc? HOT 2
- Add Next 13 support HOT 3
- Typescript support for Link properties HOT 1
- Link to dynamic route results in ERR_ABORTED 404 (Not Found), then redirects correctly HOT 2
- Incorrect translation of external links HOT 4
- How to use next-translate-routes with I18next and withPlugins? HOT 1
- [storybook] - No wrapped App component in withTranslateRoutes HOT 1
- Support for fallback / substituable language (nonExplicitSupportedLngs) HOT 9
- We support Dynamic Routes and getStaticProps Pages from next.js? HOT 9
- fileUrlToUrl breaks on 404 HOT 2
- Add support for Next 13 `/app` directory HOT 4
- Update LinkProps to support Next.js 13 <Link> component HOT 2
- Update pagesDirs to support Next.js 11 pages path HOT 1
- Next Link supports ref, but next-translate-routes does not HOT 1
- Routing does not work any more after update to next 13.3.0 HOT 7
- Add the ability to export the translations directly from the pages HOT 1
- How can I use it in storybook? HOT 1
- Static segment after dynamic segment? HOT 2
- How to work with dynamic routes? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-translate-routes.