aralroca / next-translate-plugin

Next-translate plugin for i18n in Next.js 🌍 - Load page translations and use them in an easy way!
MIT License
31 stars 18 forks source link

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

Open boredland opened 1 year ago

boredland commented 1 year ago

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 commented 1 year ago

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

AlexanderVishnevsky commented 1 year ago

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 commented 1 year ago

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