如何修复 Next.js Vercel 部署模块未找到错误 [英] How to fix Next.js Vercel deployment module not found error
问题描述
我的 next.js 应用程序可以在我的机器上运行,并且在部署到 Vercel 时可以运行,但现在在 Vercel 上构建时它会失败,并出现以下错误:
My next.js app works on my machine and was working when deployed on Vercel but now it fails when building on Vercel with the following error:
我尝试删除 node_modules 并运行 npm install
几次,但没有任何乐趣.
I've tried deleting node_modules and running npm install
a few times but with no joy.
任何帮助将不胜感激.谢谢!
Any help would be hugely appreciated. Thank you!
运行npm run build"20:43:24.926
tdwcks@1.0.0 构建/vercel/5ccaedc920:43:24.926
下一个构建20:43:24.967
内部/模块/cjs/loader.js:98320:43:24.967
抛出错误;20:43:24.967
^20:43:24.967
错误:找不到模块../build/output/log"20:43:24.967
需要堆栈:20:43:24.967
-/vercel/5ccaedc9/node_modules/.bin/next20:43:24.967
在 Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)20:43:24.967
在 Function.Module._load (internal/modules/cjs/loader.js:862:27)20:43:24.967
在 Module.require (internal/modules/cjs/loader.js:1042:19)20:43:24.967
在要求(内部/模块/cjs/helpers.js:77:18)20:43:24.967
在对象.(/vercel/5ccaedc9/node_modules/.bin/next:2:46)20:43:24.967
在 Module._compile (internal/modules/cjs/loader.js:1156:30)20:43:24.967
在 Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)20:43:24.967
在 Module.load (internal/modules/cjs/loader.js:1000:32)20:43:24.967
在 Function.Module._load (internal/modules/cjs/loader.js:899:14)20:43:24.967
在 Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {20:43:24.967
代码:'MODULE_NOT_FOUND',20:43:24.967
要求堆栈:['/vercel/5ccaedc9/node_modules/.bin/next']20:43:24.967
}20:43:24.969
npm 错误!代码生命周期20:43:24.969
npm 错误!错误号 120:43:24.970
npm 错误!tdwcks@1.0.0 构建:下一个构建
20:43:24.970
npm 错误!退出状态 120:43:24.970
npm 错误!20:43:24.970
npm 错误!tdwcks@1.0.0 构建脚本失败.20:43:24.970
npm 错误!这可能不是 npm 的问题.上面可能有额外的日志输出.20:43:24.974
npm 错误!可以在以下位置找到此运行的完整日志:20:43:24.974
npm 错误!/vercel/.npm/_logs/2020-06-17T19_43_24_971Z-debug.log20:43:24.979
错误:命令npm run build"以 1 退出20:43:25.342
[dmesg] 如下:20:43:25.342
[962.449223] ecs-bridge: 端口 1(veth2a021300) 进入禁用状态20:43:25.342
[962.453655]设备veth2a021300进入混杂模式20:43:25.342
[962.457686] ecs-bridge: 端口 1(veth2a021300) 进入阻塞状态20:43:25.342
[962.462004] ecs-bridge: 端口 1(veth2a021300) 进入转发状态20:43:26.242
完成package.json"
Running "npm run build" 20:43:24.926
tdwcks@1.0.0 build /vercel/5ccaedc9 20:43:24.926
next build 20:43:24.967
internal/modules/cjs/loader.js:983 20:43:24.967
throw err; 20:43:24.967
^ 20:43:24.967
Error: Cannot find module '../build/output/log' 20:43:24.967
Require stack: 20:43:24.967
- /vercel/5ccaedc9/node_modules/.bin/next 20:43:24.967
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15) 20:43:24.967
at Function.Module._load (internal/modules/cjs/loader.js:862:27) 20:43:24.967
at Module.require (internal/modules/cjs/loader.js:1042:19) 20:43:24.967
at require (internal/modules/cjs/helpers.js:77:18) 20:43:24.967
at Object. (/vercel/5ccaedc9/node_modules/.bin/next:2:46) 20:43:24.967
at Module._compile (internal/modules/cjs/loader.js:1156:30) 20:43:24.967
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10) 20:43:24.967
at Module.load (internal/modules/cjs/loader.js:1000:32) 20:43:24.967
at Function.Module._load (internal/modules/cjs/loader.js:899:14) 20:43:24.967
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) { 20:43:24.967
code: 'MODULE_NOT_FOUND', 20:43:24.967
requireStack: [ '/vercel/5ccaedc9/node_modules/.bin/next' ] 20:43:24.967
} 20:43:24.969
npm ERR! code ELIFECYCLE 20:43:24.969
npm ERR! errno 1 20:43:24.970
npm ERR! tdwcks@1.0.0 build:next build
20:43:24.970
npm ERR! Exit status 1 20:43:24.970
npm ERR! 20:43:24.970
npm ERR! Failed at the tdwcks@1.0.0 build script. 20:43:24.970
npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 20:43:24.974
npm ERR! A complete log of this run can be found in: 20:43:24.974
npm ERR! /vercel/.npm/_logs/2020-06-17T19_43_24_971Z-debug.log 20:43:24.979
Error: Command "npm run build" exited with 1 20:43:25.342
[dmesg] follows: 20:43:25.342
[ 962.449223] ecs-bridge: port 1(veth2a021300) entered disabled state 20:43:25.342
[ 962.453655] device veth2a021300 entered promiscuous mode 20:43:25.342
[ 962.457686] ecs-bridge: port 1(veth2a021300) entered blocking state 20:43:25.342
[ 962.462004] ecs-bridge: port 1(veth2a021300) entered forwarding state 20:43:26.242
Done with "package.json"
这是我的 Package.json
Here's my Package.json
{
"name": "tdwcks",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cjs": "0.0.11",
"core-util-is": "^1.0.2",
"framer-motion": "^1.11.0",
"gray-matter": "^4.0.2",
"next": "^9.4.4",
"raw-loader": "^4.0.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-ga": "^3.0.0",
"react-markdown": "^4.3.1",
"react-player": "^2.2.0",
"react-scripts": "^3.4.1"
},
"devDependencies": {
"postcss-preset-env": "^6.7.0",
"tailwindcss": "^1.4.6"
}
}
推荐答案
如果您不小心将 node_modules
提交到项目的 Git 存储库,通常会发生此错误.
This error typically happens if you're accidentally committing node_modules
to your project's Git Repostiory.
您可以尝试执行以下操作吗?
Could you try to do the following?
- 确保所有更改都已提交,并且您拥有一个干净的目录.
- 运行
rm -rf node_modules
(或在 Windows 上删除文件夹). - 运行
git add -A
然后git commit -m 删除所有模块文件"
. - 将
node_modules
添加到您的.gitignore
文件中(并保存). - 运行
git add -A
然后git commit -m 更新忽略的文件"
. - 通过
git status
验证您的目录是否完全干净. - 然后,运行
git push
.此部署应该可以在 Vercel 上运行. - 最后,根据您的包管理器重新运行
npm i
或yarn
以使您的本地副本正常工作.
- Ensure all changes have been committed and you have a clean directory.
- Run
rm -rf node_modules
(or delete the folder on Windows). - Run
git add -A
thengit commit -m "Remove all module files"
. - Add
node_modules
to your.gitignore
file (and save). - Run
git add -A
thengit commit -m "Update ignored files"
. - Verify your directory is completely clean via
git status
. - Then, run
git push
. This deployment should work on Vercel. - Finally, re-run
npm i
oryarn
depending on your package manager to get your local copy working.
这篇关于如何修复 Next.js Vercel 部署模块未找到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!