NextJS + Typescript 构建失败,@auth0/nextjs-auth0

时间:2021-06-14 09:58:27

标签: typescript next.js

我正在为 NextJS 使用 Typescript,但我无法构建应用程序,因为它的 auth0/nextjs-auth0 存在一些问题

这就是问题所在。如果我安装它,它会继续检查 auth0/nextjs-auth0 包中的问题。

这是错误 https://imgur.com/a/y7ft7Dq

这是我的 tsconfig.json

    {
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": [
      "es6",
      "es7",
      "esnext",
      "dom"
    ],
    "allowJs": true, /* Allow javascript files to be compiled. */// "checkJs": true,                       /* Report errors in .js files. */
    "jsx": "preserve",                  /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "removeComments": false,
    "strict": true, /* Enable all strict type-checking options. */
    "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
    "strictNullChecks": true, /* Enable strict null checks. */
    "strictFunctionTypes": true, /* Enable strict checking of function types. */
    "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
    "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
    "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. *//* Additional Checks */
    "noUnusedLocals": true, /* Report errors on unused locals. */
    "noUnusedParameters": true, /* Report errors on unused parameters. */
    "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
    "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. *//* Module Resolution Options */
    "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    "baseUrl": ".",                    /* Type declaration files to be included in compilation. */
    "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    "esModuleInterop": true,                 /* Specify the location where debugger should locate map files instead of generated locations. */
    "inlineSourceMap": true,
    "inlineSources": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "declaration": true,
    "declarationDir": "./node_modules/@auth0/nextjs-auth0/src/auth0-session",
    "declarationMap": true
  },
  "include": [
    "pages"
  ],
  "exclude": [
    "node_modules"
  ]
}

2 个答案:

答案 0 :(得分:0)

通过运行:

尝试错误消息所说的内容
npm i --save-dev @types/url-join

如果这不起作用,请尝试删除 node_modules,然后运行 ​​npm installyarn

答案 1 :(得分:0)

我建议您查看official example。我在 auth0 嵌入时遇到了类似的问题。 不要忘记您需要在 <Component> 中嵌入您的 app.js 才能使 auth0 在页面上工作 + 使用 withAuthRequired

import { UserProvider } from '@auth0/nextjs-auth0';

export default function App({ Component, pageProps }) {
  const { user } = pageProps;
  return (
      <UserProvider user={user}>
        <Component {...pageProps} />
      </UserProvider>
  );
}