NextJS Rewrites TypeError: (0 , _resolveRewrites.default) is not a function

Viewed 3781

I got an Error when using Rewrites in NextJS by using references in NextJS Documentation
I tried to reinstall node_modules but it still not working
Enviroment Variables is working, but rewrites feature is not working

This is my next.config.js

module.exports = {
  env: {
    APPNAME: 'NextJS Exercise!!!',
  },
  async rewrites() {
    return [
      {
        source: '/login',
        destination: '/auth/login',
      }, 
    ]
  },
}

This is the error what i got
TypeError: (0 , _resolveRewrites.default) is not a function

Next.config.js Code
The Error

4 Answers

I encountered this problem before with a clean nextjs project.

There is a quick fix:

  • Remove the node_modules
  • Remove package-lock.json
  • npm install again.

If the above cannot help, please try to upgrade the nextjs package to 10.2.0, npm install next@latest

I had the same issue, the solution from @Mic doesn't work unfortunately for me, but when I clean the cache first it works so run this in order

Then if you are using yarn:

yarn cache clean

rm -rf node_modules yarn.lock && yarn install

Or if you are using npm:

npm cache clean

rm -rf node_modules package-lock.json && npm install

If the quick fix from @MicFung doesn't work try using yarn.

  • Remove the node_modules
  • Remove package-lock.json and / or Remove yarn.lock
  • yarn install

Another fix could be to remove the .next map in the root of your project and rerun the start script.

Related