【问题标题】:NextJS Rewrites TypeError: (0 , _resolveRewrites.default) is not a functionNextJS Rewrites TypeError: (0 , _resolveRewrites.default) 不是函数
【发布时间】:2021-08-04 07:36:18
【问题描述】:

通过使用 NextJS 文档中的引用在 NextJS 中使用 Rewrites 时出现错误
我尝试重新安装 node_modules 但它仍然无法正常工作
环境变量有效,但重写功能无效

这是我的 next.config.js

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

这是我得到的错误
TypeError: (0 , _resolveRewrites.default) 不是函数

Next.config.js Code
The Error

【问题讨论】:

  • 删除 .next 文件夹并重新运行是否有效?

标签: javascript reactjs webpack babeljs next.js


【解决方案1】:

如果@MicFung 的快速修复不起作用,请尝试使用yarn

  • 删除 node_modules
  • 删除 package-lock.json 和/或删除 yarn.lock
  • 纱线安装

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,不幸的是,@Mic 的解决方案对我不起作用,但是当我首先清理缓存时它起作用了,所以按顺序运行它

    那么如果你使用的是纱线:

    yarn cache clean

    rm -rf node_modules yarn.lock && yarn install

    或者如果您使用的是 npm:

    npm cache clean

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

    【讨论】:

      【解决方案3】:

      我之前在干净的 nextjs 项目中遇到过这个问题。

      有一个快速修复:

      • 删除 node_modules
      • 删除 package-lock.json
      • 再次npm install

      如果以上都不能解决,请尝试将nextjs包升级到10.2.0npm install next@latest

      【讨论】:

      • 啊,我明白了,它就像一个魅力,我试图删除 node_modules 然后 npm install 之前,但不工作,它在删除 node_modules 和 package-lock.json 然后 npm install 时工作
      猜你喜欢
      • 2023-01-14
      • 2020-03-03
      • 1970-01-01
      • 2022-01-08
      • 2021-06-30
      • 2020-08-04
      • 2022-01-22
      • 2021-02-19
      • 1970-01-01
      相关资源
      最近更新 更多