Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "public" directory #523

Closed
urkopineda opened this issue Oct 8, 2019 · 7 comments · Fixed by #569
Closed

Add support for "public" directory #523

urkopineda opened this issue Oct 8, 2019 · 7 comments · Fixed by #569
Labels
help wanted Extra attention is needed

Comments

@urkopineda
Copy link

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

From nextjs 9.0.6 and above the static directory is moved to public/static. Is not mandatory to move it, but the static directory will be deprecated in the future. More information here.

Moving the static folder to public/static throws the next error:

***/app/node_modules/next-i18next/dist/commonjs/config/create-config.js:54
        throw new Error("Default namespace not found at ".concat(defaultNSPath));
        ^

Error: Default namespace not found at ***/app/static/locales/es/common.json
    at _default (***/app/node_modules/next-i18next/dist/commonjs/config/create-config.js:54:15)
    at new NextI18Next (***/app/node_modules/next-i18next/dist/commonjs/index.js:52:46)
    at Object.<anonymous> (***/app/i18n.js:12:18)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (***/app/server.js:14:14)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Describe the solution you'd like

The path ***/app/static/locales/es/common.json should be ***/app/public/static/locales/es/common.json

Describe alternatives you've considered

For an easy fix, we could keep as temp solution the locales at the static path.

Additional context

...

@isaachinman
Copy link
Contributor

PRs welcome.

@kachkaev
Copy link
Contributor

kachkaev commented Oct 8, 2019

This worked for me:

  1. Move locales to /path/to/project/public/locales/{LOCALE}/{NAMESPACE}.json

  2. In /path/to/project/src/i18n.ts :

    export const nextI18next = new NextI18next({
      // ...
      localePath: typeof window === "undefined" ? "public/locales" : "locales",
    });

@isaachinman
Copy link
Contributor

@kachkaev Yes, that will work. I think what we should do is:

  1. Change the default localePath to include public.
  2. If the default localePath is not found, try looking via the filesystem without public, and then print a console warning about deprecation

It'd be nice to support the changes to NextJs core while allowing a clear non-breaking "upgrade" path for users.

@nickrttn
Copy link

This worked for me:

1. Move `locales` to `/path/to/project/public/locales/{LOCALE}/{NAMESPACE}.json`

2. In `/path/to/project/src/i18n.ts` :
   ```ts
   export const nextI18next = new NextI18next({
     // ...
     localePath: typeof window === "undefined" ? "public/locales" : "locales",
   });
   ```

You can also check for process.browser, which is added by Next.js. If the module is on the client, that boolean will be true.

I found that this doesn't work on Now where, when built, the localePath for the server needs to be locales as well.

@isaachinman
Copy link
Contributor

Thanks @nickrttn. The last bit about now deployments is interesting - @wootsbot are you aware of this? Can we detect now deployment envs?

@nickrttn
Copy link

I was still deploying my Next.js app as serverless lambda's, should probably compile to a server target 😊

@isaachinman isaachinman added the help wanted Extra attention is needed label Nov 14, 2019
@wootsbot
Copy link
Contributor

Thanks @nickrttn. The last bit about now deployments is interesting - @wootsbot are you aware of this? Can we detect now deployment envs?

I'm sorry, I think it's been a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
5 participants