Next-i18next: Updating to v0.46 causes "NextI18Next is not a constructor"

Created on 13 Jul 2019  路  3Comments  路  Source: isaachinman/next-i18next

Hi there! First of: Nice work with the library!

Describe the bug

I have an application on Next.js v8 with next-i18next v0.44 and the following i18n.js file:

const NextI18Next = require('next-i18next/dist/commonjs')

module.exports = new NextI18Next({
  defaultLanguage: 'en',
  otherLanguages: ['de'],
  // see: https://github.com/isaachinman/next-i18next/issues/328
  localePath: process.browser ? 'static/locales' : 'src/nextjs/static/locales',
})

I wanted to update to Next.js v9 (which went smoothly) and afterwards updated next-i18next to v0.46.
After doing that and trying to start up the server I got the following error:

> node ./src/nextjs/server.js

/src/nextjs/i18n.js:3
module.exports = new NextI18Next({
                 ^

TypeError: NextI18Next is not a constructor
    at Object.<anonymous> (src/nextjs/i18n.js:3:18)

Occurs in next-i18next version

0.46

Any idea what may be causing this behaviour?

Most helpful comment

Look at the updated example.

const NextI18Next = require('next-i18next').default.

All 3 comments

Look at the updated example.

const NextI18Next = require('next-i18next').default.

Gotcha, thanks for the quick feedback!

NextJs has updated their internal Babel setup, so module resolution is indeed slightly different. There are probably improvements to be made here, but as long as we have to export to a CJS target, things will be slightly weird.

Was this page helpful?
0 / 5 - 0 ratings