question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide the possibility to include json files inside /public/static/locales/ folder in the vercel lambda

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

When deploying a next-i18next translated project to vercel, the serverless lambda doesn’t include the .json translation files located under public/static/locales. Thus, following error arises every time when deploying to vercel: Screenshot_2020-06-01 Serverless Functions – Vercel

The creator of next-i18next recommended to reach out to the vercel team. A user then created a issue dedicated to this on the vercel repo . Here, @paulogdm noted that this is due to a known next.js framework limitation, captured in [vercel/next.js#8251].

Unfortunately, there’s no real solution or workaround for this problem yet. I opened a new issue for this to give this problem more attention, because no user of next-i18next is able to deploy to vercel because of this framework limitation.

Describe the solution you’d like

  • somehow configure that vercel should include all files inside public/static/locales in the serverless lambda

Describe alternatives you’ve considered

I tried to manually import the language files as suggested here, but the containing folder is still not detected (the error stays the same)

Additional context

Folder structure: Bildschirmfoto von 2020-06-01 10-22-38

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
Timercommented, Jul 8, 2020

I’ve just done a deep inspection of the code and there is nothing that explicitly tells Next.js that you’d be looking for files in that directory. This seems to be an implicit dependency of the library.

This is an intended design detail!

Adding the following lines will fix the files being missing:

diff --git a/i18n.js b/i18n.js
index 30c71f4..dab2492 100644
--- a/i18n.js
+++ b/i18n.js
@@ -1,6 +1,10 @@
 const I18N = require('next-i18next').default;
 const { localeSubpaths } = require('next/config').default().publicRuntimeConfig;
 
+// Tell Next.js these files will be read at runtime by the below code:
+const path = require('path');
+path.resolve('./public/static/locales/');
+
 const i18nInstance = new I18N({
   defaultLanguage: 'en',
   otherLanguages: ['de'],

path.resolve is the necessary code here!

6reactions
derek-fongcommented, Jun 7, 2020

Ran into the exact problem today and found this open issue. Sounds like deploying i18n-enabled solutions to Vercel is not an option until this problem is resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I use files in Serverless Functions on Vercel?
Learn how to import files inside Serverless Functions on Vercel. ... In this case, you can use the /tmp folder available with serverless...
Read more >
How to Load Data from a File in Next.js – Vercel Docs
A possible solution is to: Store your json files in a private folder inside your application; Construct an API endpoint to load these...
Read more >
Project Config with vercel.json
The vercel.json configuration file lets you configure, and override the default behavior of Vercel from within your project. This includes settings for:.
Read more >
File System API (v2) – Vercel Docs
Learn how to integrate with Vercel's File System API.
Read more >
Serverless Functions – Vercel Docs
js API Route as a Serverless Function, you can create a new file inside the /pages/api folder. The following example uses TypeScript. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found