Vercel deployment error: Module Not Found remotelly works locally. Cached build is the problem?
Vercel deployment error: Module Not Found remotelly works locally. Cached build is the problem?
我正在使用 Next.JS 托管 @ Vercel 制作此网站。我正在使用的其中一个包是一个自定义包,我已经分叉它,在我的项目中更新它,并且在构建之后,能够使其在本地工作。我发布了一篇关于它的 。
但是,部署在 Vercel 方面失败,并显示一条消息,抱怨找不到我正在使用的相同自定义模块。在本地一切正常。
14:40:04.802 Failed to compile.
14:40:04.803 ModuleNotFoundError: Module not found: Error: Can't resolve 'react-headroom' in '/vercel/path0/src/components/layout'
14:40:04.803 > Build error occurred
14:40:04.804 Error: > Build failed because of webpack errors
14:40:04.805 at /vercel/path0/node_modules/next/dist/build/index.js:17:924
14:40:04.805 at runMicrotasks (<anonymous>)
14:40:04.805 at processTicksAndRejections (internal/process/task_queues.js:95:5)
14:40:04.805 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
我认为这是由于以前版本的缓存构建所致(在我分叉和编辑我的包之前)。我遇到了一些解决方案,比如使用 Vercel CLI 来清理缓存的构建,但它似乎不起作用 (vercel --force
),因为我在构建时遇到了同样的错误。
我不确定我能做些什么来解决这个问题,或者这个过程中是否遗漏了什么。
编辑:这是我的 package.json 文件
{
"name": "cms-sanity",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "npm run build:sanity && pwd && npm run build:web",
"build:web": "next build",
"start:web": "next start",
"build:sanity": "cd studio && sanity build ../public/studio -y && cd ..",
"start:sanity": "cp .env ./studio/.env.development && cd studio && sanity start",
"postinstall": "lerna bootstrap"
},
"dependencies": {
"@chakra-ui/icons": "^1.0.15",
"@chakra-ui/react": "^1.6.7",
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@sanity/block-content-to-react": "^3.0.0",
"@sanity/client": "^2.8.0",
"@sanity/image-url": "^0.140.19",
"axios": "^0.22.0",
"classnames": "^2.2.6",
"date-fns": "^2.15.0",
"framer-motion": "^4",
"fs": "^0.0.1-security",
"google-spreadsheet": "^3.1.15",
"next": "^10.2.0",
"next-sanity": "^0.1.5",
"next-sanity-image": "^3.1.6",
"next-seo": "^4.26.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-headroom": "https://github.com/eduoliveira85/react-headroom/",
"react-hook-form": "^7.3.6",
"react-icons": "^4.2.0",
"react-jss": "^10.8.0",
"react-world-flags": "^1.4.0",
"swr": "^0.5.5"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^4.0.3",
"@sanity/cli": "^2.0.5",
"lerna": "^4.0.0",
"postcss-preset-env": "^6.7.0"
}
}
您的 package.json 中的 @react-headroom 依赖项指向 github link 而不是依赖项版本。这似乎是问题所在。
我只将文件从 repo 复制到我的项目,手动安装依赖项,这解决了问题。无论如何都不需要更新这个库。
我正在使用 Next.JS 托管 @ Vercel 制作此网站。我正在使用的其中一个包是一个自定义包,我已经分叉它,在我的项目中更新它,并且在构建之后,能够使其在本地工作。我发布了一篇关于它的
但是,部署在 Vercel 方面失败,并显示一条消息,抱怨找不到我正在使用的相同自定义模块。在本地一切正常。
14:40:04.802 Failed to compile.
14:40:04.803 ModuleNotFoundError: Module not found: Error: Can't resolve 'react-headroom' in '/vercel/path0/src/components/layout'
14:40:04.803 > Build error occurred
14:40:04.804 Error: > Build failed because of webpack errors
14:40:04.805 at /vercel/path0/node_modules/next/dist/build/index.js:17:924
14:40:04.805 at runMicrotasks (<anonymous>)
14:40:04.805 at processTicksAndRejections (internal/process/task_queues.js:95:5)
14:40:04.805 at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/telemetry/trace/trace.js:6:584)
我认为这是由于以前版本的缓存构建所致(在我分叉和编辑我的包之前)。我遇到了一些解决方案,比如使用 Vercel CLI 来清理缓存的构建,但它似乎不起作用 (vercel --force
),因为我在构建时遇到了同样的错误。
我不确定我能做些什么来解决这个问题,或者这个过程中是否遗漏了什么。
编辑:这是我的 package.json 文件
{
"name": "cms-sanity",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "npm run build:sanity && pwd && npm run build:web",
"build:web": "next build",
"start:web": "next start",
"build:sanity": "cd studio && sanity build ../public/studio -y && cd ..",
"start:sanity": "cp .env ./studio/.env.development && cd studio && sanity start",
"postinstall": "lerna bootstrap"
},
"dependencies": {
"@chakra-ui/icons": "^1.0.15",
"@chakra-ui/react": "^1.6.7",
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@sanity/block-content-to-react": "^3.0.0",
"@sanity/client": "^2.8.0",
"@sanity/image-url": "^0.140.19",
"axios": "^0.22.0",
"classnames": "^2.2.6",
"date-fns": "^2.15.0",
"framer-motion": "^4",
"fs": "^0.0.1-security",
"google-spreadsheet": "^3.1.15",
"next": "^10.2.0",
"next-sanity": "^0.1.5",
"next-sanity-image": "^3.1.6",
"next-seo": "^4.26.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-headroom": "https://github.com/eduoliveira85/react-headroom/",
"react-hook-form": "^7.3.6",
"react-icons": "^4.2.0",
"react-jss": "^10.8.0",
"react-world-flags": "^1.4.0",
"swr": "^0.5.5"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^4.0.3",
"@sanity/cli": "^2.0.5",
"lerna": "^4.0.0",
"postcss-preset-env": "^6.7.0"
}
}
您的 package.json 中的 @react-headroom 依赖项指向 github link 而不是依赖项版本。这似乎是问题所在。
我只将文件从 repo 复制到我的项目,手动安装依赖项,这解决了问题。无论如何都不需要更新这个库。