nextjs-在开发模式下使用_error.js

错误处理 React.js

蛋蛋猿

2020-03-24

因此,我在nextjs应用程序上创建了一个自定义错误页面。按照文档进行操作后,我创建了一个_error.js带有视图文件(在中React

我的问题是,当我处于开发人员模式时,我的_error页面将被完全忽略(即使它通过getInitialProps)。render函数似乎被忽略,而是nextjs在使用其内部error-debug页面。

如果我是对的,那么这就是仓库中的代码(当前版本的第84行)

当我以productionenv编译时,没问题,我的自定义错误页面被选中。

关于如何在开发人员模式下呈现自定义错误页面的任何想法?

第3297篇《nextjs-在开发模式下使用_error.js》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

2个回答
番长 2020.03.24

为了更轻松地调试,您可以在中创建新脚本package.json

...

  "scripts": {
     "dev": "next",
     "build": "next build",
     "start": "NODE_ENV=production next start",
     "prod": "npm run build; npm run start", // combine build and start in order to have easier debugging
  }

...
Tony凯 2020.03.24

明确将节点环境设置为生产环境。package.json以下脚本中,在dev命令之前添加NODE_ENV=production ...

只是我的猜测。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android