Next-i18next: Cannot get it installed for hours already

Created on 20 Jan 2020  路  2Comments  路  Source: isaachinman/next-i18next

My _app.js file

import React from 'react';
import App from 'next/app';
import appWithTranslation from "../i18n";
import "bootstrap/dist/css/bootstrap.css";

class MyApp extends App {
    render() {
        const { Component, pageProps } = this.props;
        return <Component {...pageProps} />;
    }
}

export default appWithTranslation(MyApp);

And ../i18n.js in the project root

const NextI18Next = require("next-i18next").default;

module.exports = new NextI18Next({
    defaultLanguage: "en",
    defaultNS: "common",
    localePath: "public/static/locales",
    otherLanguages: ["ru"],
    localeSubpaths: {
        en: "en",
        ru: "ru"
    }
});

Server.js is a copy-paste from your quick start tutorial

I have this error.

[ error ] TypeError: _i18n__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function
    at Module../pages/_app.js (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:1871:108)
    at __webpack_require__ (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:23:31)
    at Object.0 (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:1896:18)
    at __webpack_require__ (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:23:31)
    at /mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:91:18
    at Object.<anonymous> (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:94:10)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.loadComponents (/mnt/c/OSPanel/domains/test-next/node_modules/next/dist/next-server/server/load-components.js:24:20)
    at DevServer.findPageComponents (/mnt/c/OSPanel/domains/test-next/node_modules/next/dist/next-server/server/next-server.js:514:40)
    at DevServer.renderErrorToHTML (/mnt/c/OSPanel/domains/test-next/node_modules/next/dist/next-server/server/next-server.js:652:35)
TypeError: _i18n__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function
    at Module../pages/_app.js (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:1871:108)
    at __webpack_require__ (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:23:31)
    at Object.0 (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:1896:18)
    at __webpack_require__ (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:23:31)
    at /mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:91:18
    at Object.<anonymous> (/mnt/c/OSPanel/domains/test-next/.next/server/static/development/pages/_app.js:94:10)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.loadComponents (/mnt/c/OSPanel/domains/test-next/node_modules/next/dist/next-server/server/load-components.js:24:20)
    at DevServer.findPageComponents (/mnt/c/OSPanel/domains/test-next/node_modules/next/dist/next-server/server/next-server.js:514:40)
    at DevServer.renderErrorToHTML (/mnt/c/OSPanel/domains/test-next/node_modules/next/dist/next-server/server/next-server.js:652:35)

When I change in _app.js

export default appWithTranslation(MyApp);

to

export default MyApp;

The error is gone.

All 2 comments

This is about module resolution and will depend on your individual use case. I suggest you post on StackOverflow.

I have hello world next app. I do not have anything extra. It is not a complicated setup.

besides it obviously has something to do with default not a function here.

const NextI18Next = require("next-i18next").default;
Was this page helpful?
0 / 5 - 0 ratings