Skip to content

Importing createMiddleware() doesn't work as the tutorial suggests in type:module packages #1153

Description

@DamienCassou

Description

In a type:module package, the suggested way to import createMiddleware() doesn't work.

Workaround1: Remove the type:module line of your package.json

Workaround2: Change the suggested middleware.js file to something like

import middleware from "next-intl/middleware";

const createMiddleware = middleware.default;

export default createMiddleware({...});

Verifications

  • I've verified that the problem I'm experiencing isn't covered in the docs.
  • I've searched for similar, existing issues on GitHub and Stack Overflow.
  • I've compared my app to a working example to look for differences.

Mandatory reproduction URL

https://github.com/DamienCassou/next-intl-issue-createMiddleware

Reproduction description

Steps to reproduce:

  1. clone the reproduction project
  2. type yarn
  3. type yarn run dev
  4. open http://localhost:3000

Actual behavior:

TypeError: next_intl_middleware__WEBPACK_IMPORTED_MODULE_0__ is not a function

src/middleware.js (3:1) @ <unknown>

  1 | import createMiddleware from 'next-intl/middleware';
  2 |
> 3 | export default createMiddleware({
    | ^
  4 |   // A list of all locales that are supported
  5 |   locales: ['en', 'de'],
  6 |

Expected behaviour

I see the content of Page.jsx in English.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions