next-i18next: Error: Cannot find module 'next-i18next/middleware'

I followed every step in configuration, have the same setup for server.js and i18n.js but still getting this error whenever I try to run yarn dev:

module.js:550
    throw err;
    ^

Error: Cannot find module 'next-i18next/middleware'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/dev/Projekty/AdTom/front/app.js:3:31)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)

This is my server.js:

const express = require('express')
const next = require('next')
const nextI18NextMiddleware = require('next-i18next/middleware')

const nextI18next = require('./lib/i18n')

const app = next({ dev: process.env.NODE_ENV !== 'production' })
const handle = app.getRequestHandler();

(async () => {
  await app.prepare()
  const server = express()

  nextI18NextMiddleware(nextI18next, app, server)

  server.get('*', (req, res) => handle(req, res))

  await server.listen(3000)
})()

and these are package versions:

node: 8.14.0

"express": "^4.16.4"
"next": "^7.0.2"
"next-i18next": "^0.8.0"
"react": "^16.6.3"

What else needs to be done to run it ?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Hi @isaachinman, could you please add an example that uses the latest version of next-i18next (v6) with a custom express server? I keep going around in circles trying to get this to work. Thanks

@lcvbeek It’s not “supported” anymore because it’s not necessary. We were able to replace the functionality with built-in features of NextJs, as soon as rewrites dropped. The middleware you mentioned is already/still used by next-i18next, just in a serverless manner.

You can still use a custom server if you really want to, but next-i18next no longer has anything to do with that.

Let me know if that makes sense.

Apologies, the master branch documentation has gotten ahead of the current release (v0.8.0) and I had not realised that npm links back here.

I’m releasing v0.9.0 now, please try again in a few minutes.

In the future we’ll need to keep releases on branches due to this documentation problem, I suppose.

@St1myL The v5 and v6 releases do not support custom servers anymore. They’re entirely serverless.

Great, I am sorry for the inconvenience. I hope the package saves you some time and headache.