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

Created on 11 Dec 2018  ·  19Comments  ·  Source: isaachinman/next-i18next

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 ?

Most helpful comment

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

All 19 comments

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.

@pippo111 Would appreciate if you can let me know if everything goes smoothly!

@isaachinman Thank you! After updating to v0.9.0 everything is working as expected.

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

@isaachinman , version 6.0.0+ lacks middleware file:

image

And I have to import like this: import { nextI18NextMiddleware } from 'next-i18next/dist/commonjs/middlewares'
instead of: import nextI18NextMiddleware from 'next-i18next/middleware'

Maybe I missed something

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

@isaachinman how so?
I keep seeing the key (with _view-source://url.._)
image

image
image

I'm not using the middleware, but.. is there something I need to do to enable server-side rendering?

In the client it works fine
Although I can actually see the key before the value gets rendered on page load.

@mqtik If you believe you've found a bug, please open a new issue. SSR is supported by default, of course.

I get this issue after I upgraded to the version 6.0.2 from 4.5.0 @isaachinman

Is there anything I have to do after upgrading? @isaachinman

@sarang-naico You will need to follow the updated documentation and remove your custom server (or at least stop using the next-i18next middleware there).

@isaachinman I will check that, Thank you!

Is there any documentation as to why it's no longer supported? Could we migrate to https://github.com/i18next/i18next-http-middleware? Are there any caveats that I'm not aware of?

@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.

@isaachinman Thanks for the quick reply. Makes sense. 👍

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

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

Same here...

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

I would really appreciate that

@lucasm08 What problem are you having? This package is now completely unrelated to Express or custom servers – the two concerns should not be related.

Was this page helpful?
0 / 5 - 0 ratings