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

next-translate overrides next config when passed a config function #4

Open
boredland opened this issue Jan 4, 2023 · 3 comments
Open
Assignees

Comments

@boredland
Copy link

boredland commented Jan 4, 2023

What version of this package are you using?

1.6.0

What operating system, Node.js, and npm version?

linux, node 16, npm 8

What happened?

the next config can either be an object:

const nextConfig = {
  /* config options here */
}

module.exports = nextConfig

or a (async) function:

module.exports = (phase, { defaultConfig }) => {
  /**
   * @type {import('next').NextConfig}
   */
  const nextConfig = {
    /* config options here */
  }
  return nextConfig
}

both examples are from the next documentation.

When passing a function to next-translate tho, it replaces that function with an object, discarding all the previous content.

I prepared a minimal reproduction here.

What did you expect to happen?

I expected the config to be extended either way.

Other config wrappers, like @sentry/nextjs, work like that.

Are you willing to submit a pull request to fix this bug?

If this is confirmed indeed a bug, I give it a try.

@aralroca
Copy link
Owner

aralroca commented Jan 9, 2023

Feel free to PR to adapt this config property https://github.com/aralroca/next-translate/blob/master/src/plugin/index.ts#L5

@AlexanderVishnevsky
Copy link

any updates? Faced with same problem when adding next-translate plugin to next.config

next-translate plugin overrides nextConfig

const nextTranslate = require('next-translate');
const nextConfig = {};

if (process.env.NODE_ENV !== 'development') {
    nextConfig.assetPrefix = '/appName';
    nextConfig.rewrites = async () => {
        return [
            { source: '/appName/_next/:path*', destination: '/_next/:path*' },
            { source: '/appName/static/:path*', destination: '/static/:path*' },
        ];
    };
}

module.exports = nextTranslate({ ...nextConfig });

@aralroca
Copy link
Owner

aralroca commented Feb 1, 2023

any updates? Faced with same problem when adding next-translate plugin to next.config

next-translate plugin overrides nextConfig

const nextTranslate = require('next-translate');
const nextConfig = {};

if (process.env.NODE_ENV !== 'development') {
    nextConfig.assetPrefix = '/appName';
    nextConfig.rewrites = async () => {
        return [
            { source: '/appName/_next/:path*', destination: '/_next/:path*' },
            { source: '/appName/static/:path*', destination: '/static/:path*' },
        ];
    };
}

module.exports = nextTranslate({ ...nextConfig });

This looks like a different error. We are supporting Next.js configuration and rewrites should work, but remember that adding the locales these rewrites should be adapted to the locales. You should add locales: false on you rewrites, otherwise is looking /en/_next/:path*. This is documented in the Next.js core documentation of rewrites: https://nextjs.org/docs/api-reference/next.config.js/rewrites#rewrites-with-i18n-support

@aralroca aralroca transferred this issue from aralroca/next-translate Feb 20, 2023
@aralroca aralroca self-assigned this Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants