【问题标题】:Deployment on Vercel with Auth0: Can't resolve '@auth0/nextjs-auth0' in '/vercel/path0/pages'使用 Auth0 在 Vercel 上部署:无法解析“/vercel/path0/pages”中的“@auth0/nextjs-auth0”
【发布时间】:2021-08-19 10:28:48
【问题描述】:

我有一个项目已经部署在 Vercel 上。自上周以来,我一直致力于改进布局,目标是完成该项目的 MVP。所以,我改变了我对 auth0 的使用,使用包为 nextjs @auth0/nextjs-auth0。我跑了

npm install @auth0/nextjs-auth0

我的 package.json 上有

{
  "name": "MAmanager",
  "version": "1.0.0",
  "engines": {
    "node": "14.x",
    "npm": "6.x"
  },
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "next",
    "start": "next start",
    "build": "next build"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@auth0/nextjs-auth0": "github:auth0/nextjs-auth0",
    "dayjs": "^1.9.5",
    "formik": "^2.1.5",
    "next": "^10.2.3",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-icons": "^4.2.0",
    "swr": "^0.5.6",
    "yup": "^0.29.3"
  },
  "devDependencies": {
    "autoprefixer": "^10.2.5",
    "postcss": "^8.3.0",
    "tailwindcss": "^2.1.2"
  }
}

我的页面上的用法是

import { UserProvider } from '@auth0/nextjs-auth0'
import { useUser } from '@auth0/nextjs-auth0'
import { withPageAuthRequired } from '@auth0/nextjs-auth0'

当我在 Vercel 上部署我的分支时出现此错误

08:57:49.989    Failed to compile.
08:57:49.990    ModuleNotFoundError: Module not found: Error: Can't resolve '@auth0/nextjs-auth0' in '/vercel/path0/pages'
08:57:49.990    > Build error occurred
08:57:49.991    Error: > Build failed because of webpack errors
08:57:49.991        at /vercel/path0/node_modules/next/dist/build/index.js:17:924
08:57:49.991        at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
08:57:50.020    error Command failed with exit code 1.

我看到过由大小写差异引起的错误,但我不明白这里发生了什么。感谢您的帮助。

【问题讨论】:

    标签: javascript node.js next.js node-modules auth0


    【解决方案1】:

    在查看其他示例后,我刚刚手动编辑了 package.json。

    运行npm install @auth0/nextjs-auth0 后,自动添加了包"@auth0/nextjs-auth0": "github:auth0/nextjs-auth0",

    我只是编辑到

    "@auth0/nextjs-auth0": "^1.3.1"
    

    并致力于部署。

    注意:安装包的方式在本地主机中的 dev 上工作,但仅在部署时中断。

    【讨论】:

      【解决方案2】:

      尝试为您的部署制作自定义构建脚本作为临时解决方法:

      npm install && npm i @auth0/nextjs-auth0@1.3.1 && npm run build
      

      这可以使用自定义构建命令在部署设置选项卡下添加以进行生产。在 npm 之后运行特定的目标包版本安装我应该覆盖在 prod 中安装的有问题的版本

      【讨论】:

        猜你喜欢
        • 2020-09-16
        • 1970-01-01
        • 2019-05-24
        • 2016-11-19
        • 2022-10-16
        • 2022-01-02
        • 2021-05-23
        • 2020-08-30
        • 2017-07-01
        相关资源
        最近更新 更多