Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 518
Fendy Fernandy Avatar asked May 14 '21 04:05

Fendy Fernandy


2 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

like image 137
Mic Fung Avatar answered Nov 18 '22 02:11

Mic Fung


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

like image 37
medhatdawoud Avatar answered Nov 18 '22 03:11

medhatdawoud