小编Aid*_*hsy的帖子

下一页 13.4 错误:API 路由中的 NEXT_REDIRECT

我的 /app/api/auth/route.ts 文件:

import { redirect } from 'next/navigation';

export async function GET(req: Request) {
  try {
    redirect('/dashboard');
  } catch (error) {
    console.log(error);
    redirect('/');
  }
}
Run Code Online (Sandbox Code Playgroud)

我意识到当我在 try catch 中进行重定向时,我收到错误:

Error: NEXT_REDIRECT
    at getRedirectError (webpack-internal:///(sc_server)/./node_modules/next/dist/client/components/redirect.js:40:19)
    at redirect (webpack-internal:///(sc_server)/./node_modules/next/dist/client/components/redirect.js:46:11)
    at GET (webpack-internal:///(sc_server)/./app/api/auth/route.ts:23:66)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async eval (webpack-internal:///(sc_server)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:244:37) {
  digest: 'NEXT_REDIRECT;replace;/dashboard'
}
Run Code Online (Sandbox Code Playgroud)

当我摆脱 try catch 时,一切正常:

export async function GET(req: Request) {
  redirect('/dashboard')
}
Run Code Online (Sandbox Code Playgroud)

这按预期工作。我需要尝试并捕获,因为这是一个身份验证路由,并且我需要一些错误处理,因为请求可能会失败,我省略了身份验证功能,因为我意识到这只是在简单的尝试和捕获上发生的。

或者,如果 Next 13 在 /api 路由中有另一种错误处理方式,请告诉我。

next.js

32
推荐指数
3
解决办法
4万
查看次数

如何在 VSCode 中禁用风筝提示片段设置?

Kite 的最新更新在光标所在的每一行的右侧添加了一个提示功能。 图片1, 图像2,这变得非常烦人。我想继续使用 Kite,但我不希望这个“在中查找相关代码”跟随光标移动。

kite visual-studio-code

17
推荐指数
2
解决办法
1584
查看次数

如何禁用 .eslintrc.js 中 '{'.eslintobject-curly-spacing 之后不应有空格

我正在使用 prettier,并使用 firebase init 和 eslint 选项初始化了我的项目。但是当我保存文件时,prettier 扩展会在对象花括号中添加间距,如下所示:

export { basicHTTP } from './http';
Run Code Online (Sandbox Code Playgroud)

哪个 eslint 给了我一个错误:eslint 错误有没有办法禁用这个?

这是我的 .eslintrc.js 文件,它与 firebase init 一起提供:

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    'eslint:recommended',
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:import/typescript',
    'google',
  ],
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: ['tsconfig.json', 'tsconfig.dev.json'],
    tsconfigRootDir: __dirname,
    sourceType: 'module',
  },
  ignorePatterns: [
    '/lib/**/*', // Ignore built files.
  ],
  plugins: ['@typescript-eslint', 'import'],
  rules: {
    quotes: ['error'],
  },
};
Run Code Online (Sandbox Code Playgroud)

eslint visual-studio-code prettier eslintrc

10
推荐指数
1
解决办法
1万
查看次数

浏览器列表:caniuse-lite 已过时。请运行: npx browserslist@latest --update-db NextJS

当我运行 NextJs 程序时,总是会弹出这个错误

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Run Code Online (Sandbox Code Playgroud)

然后我在 shell 中运行 npx browserslist@latest --update-db :

npx: installed 6 in 1.905s
Current version: 1.0.30001179
New version:     1.0.30001179
Removing old caniuse-lite from lock file
Installing new caniuse-lite version
$ npm install caniuse-lite
Cleaning package.json dependencies from caniuse-lite
$ npm uninstall caniuse-lite
caniuse-lite has been successfully updated

No target browser changes
Run Code Online (Sandbox Code Playgroud)

当我再次运行我的 Next 程序时,会发生同样的错误。这昨天开始发生在我身上。我只使用了 npx create-next-app 和 npm run dev。

next.js

8
推荐指数
1
解决办法
6818
查看次数

标签 统计

next.js ×2

visual-studio-code ×2

eslint ×1

eslintrc ×1

kite ×1

prettier ×1