小编aso*_*rov的帖子

找不到模块“next”或其相应的类型声明

Cannot find module '' or its corresponding type declarations.在Next.js项目中导入时获取。

每次导入都会发生这种情况。预览

纱线版本:3.1.0-rc.2
下一版本:11.1.2

tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "importHelpers": true,
    "jsx": "preserve",
    // "baseUrl": "src"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ],
}
Run Code Online (Sandbox Code Playgroud)

typescript reactjs tsconfig yarnpkg next.js

22
推荐指数
4
解决办法
5万
查看次数

在 `try` 内发生错误,未由 `catch` 处理

我希望块内抛出的特定错误try不被处理catch(err)

例子:

const someFunc = async () => {
  ...
  try {
    ...
    // This error should not be handled by the catch and go straight to the middleware
    throw {
      status: 404,
      message: "Not Found",
    };
  } catch (error) {
    throw {
      status: 500,
      message: "Something went wrong",
      reason: error,
    };
  }
};
Run Code Online (Sandbox Code Playgroud)

之后中间件处理错误。

export const errorHandler: ErrorRequestHandler = (err, req, res, next) => {
  const { status = 500, message, reason } = err;
  res.status(status).json({ …
Run Code Online (Sandbox Code Playgroud)

javascript error-handling express typescript

0
推荐指数
1
解决办法
969
查看次数