Next.js构建失败。窗口未定义
我正在构建一个next.js应用程序,并且在开发模式下它非常完美。部署到生产时,它失败了以下错误:
[ ] info - Generating static pages (0/6)/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:220
_ref5 = options !== null && options !== void 0 ? options : {}, _ref5$callbackUrl = _ref5.callbackUrl, callbackUrl = _ref5$callbackUrl === void 0 ? window.location.href : _ref5$callbackUrl, _ref5$redirect = _ref5.redirect, redirect = _ref5$redirect === void 0 ? true : _ref5$redirect;
^
ReferenceError: window is not defined
at _callee5$ (/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:220:160)
at tryCatch (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
at Generator._invoke (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
at Generator.next (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
at asyncGeneratorStep (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
at /home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
at new Promise (<anonymous>)
at /home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12
at _signIn (/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:329:18)
[= ] info - Generating static pages (0/6)/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:220
_ref5 = options !== null && options !== void 0 ? options : {}, _ref5$callbackUrl = _ref5.callbackUrl, callbackUrl = _ref5$callbackUrl === void 0 ? window.location.href : _ref5$callbackUrl, _ref5$redirect = _ref5.redirect, redirect = _ref5$redirect === void 0 ? true : _ref5$redirect;
我该怎么办?什么都不了解..
I'm building a next.js app and it works perfect in development mode. While deploying to production it fails with the following error:
[ ] info - Generating static pages (0/6)/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:220
_ref5 = options !== null && options !== void 0 ? options : {}, _ref5$callbackUrl = _ref5.callbackUrl, callbackUrl = _ref5$callbackUrl === void 0 ? window.location.href : _ref5$callbackUrl, _ref5$redirect = _ref5.redirect, redirect = _ref5$redirect === void 0 ? true : _ref5$redirect;
^
ReferenceError: window is not defined
at _callee5$ (/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:220:160)
at tryCatch (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:86:17)
at Generator._invoke (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:66:24)
at Generator.next (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:117:21)
at asyncGeneratorStep (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (/home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
at /home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7
at new Promise (<anonymous>)
at /home/ec2-user/groot-dashboard/node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12
at _signIn (/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:329:18)
[= ] info - Generating static pages (0/6)/home/ec2-user/groot-dashboard/node_modules/next-auth/react/index.js:220
_ref5 = options !== null && options !== void 0 ? options : {}, _ref5$callbackUrl = _ref5.callbackUrl, callbackUrl = _ref5$callbackUrl === void 0 ? window.location.href : _ref5$callbackUrl, _ref5$redirect = _ref5.redirect, redirect = _ref5$redirect === void 0 ? true : _ref5$redirect;
What should i do? Can't understand anything..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您不显示导致错误的代码时,很难为您提供帮助...
当我想我认为您正在使用窗口时。 则可以使用
或使用使用效果挂钩的更具体的帮助:)
如果您提供代码的某些部分,
It is very hard to help you when you are not showing the code that causes the error ...
When I guess I think you are using window.* in your code and this is not available at build time so one way is to check if it is existing with
or use the useEffect hook
If you provide some parts of your code more specific help is possible :)