使用 Auth0 在 Vercel 上部署:无法解析“/vercel/path0/pages”中的“@auth0/nextjs-auth0”
Deployment on Vercel with Auth0: Can't resolve '@auth0/nextjs-auth0' in '/vercel/path0/pages'
我有一个已经部署在 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 上部署我的 b运行ch 时,我得到了这个错误
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.
我看到过类似由大小写差异引起的错误,但我不明白这里发生了什么。感谢您的帮助。
看到其他示例后,我手动编辑了 package.json。
在 运行 npm install @auth0/nextjs-auth0
之后自动添加包 "@auth0/nextjs-auth0": "github:auth0/nextjs-auth0",
。
我刚编辑到
"@auth0/nextjs-auth0": "^1.3.1"
并致力于部署。
注意:包的安装方式适用于本地主机中的开发,但仅在部署时中断。
尝试为您的部署制作自定义构建脚本作为临时解决方法:
npm install && npm i @auth0/nextjs-auth0@1.3.1 && npm run build
这可以使用自定义构建命令添加到部署设置选项卡下以进行生产。 运行 在 npm 之后安装的特定目标包版本我应该覆盖 prod 中安装的有问题的版本
我有一个已经部署在 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 上部署我的 b运行ch 时,我得到了这个错误
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.
我看到过类似由大小写差异引起的错误,但我不明白这里发生了什么。感谢您的帮助。
看到其他示例后,我手动编辑了 package.json。
在 运行 npm install @auth0/nextjs-auth0
之后自动添加包 "@auth0/nextjs-auth0": "github:auth0/nextjs-auth0",
。
我刚编辑到
"@auth0/nextjs-auth0": "^1.3.1"
并致力于部署。
注意:包的安装方式适用于本地主机中的开发,但仅在部署时中断。
尝试为您的部署制作自定义构建脚本作为临时解决方法:
npm install && npm i @auth0/nextjs-auth0@1.3.1 && npm run build
这可以使用自定义构建命令添加到部署设置选项卡下以进行生产。 运行 在 npm 之后安装的特定目标包版本我应该覆盖 prod 中安装的有问题的版本