我遇到的问题部署到Vercel做出一些改变后。运行与npm run dev
工作,但部署到Vercel(与npm run build
运行)后,它咳出一个错误:
09:53:00.125 TypeError: Cannot read property 'hash' of null09:53:00.125 at callback (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:59190:46)09:53:00.125 at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:57683:3909:53:00.125 at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:135587:509:53:00.125在胡克。eval [as callAsync] (eval at create (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:33832:10),:6:1)[09:53:00.126]_handleResult (/vercel/path0/node_modules/下/dist/编译/webpack/bundle5.js: 135557:21)09:53:00.126 at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:135540:1109:53:00.126 at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:59794:14[09:53:00.126] at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:59452:609:53:00.126 at done (/vercel/path0/node_modules/next/dist/compiled/neo-async/async.js:1:10308)09:53:00.126 at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:59356:13[09:53:00.126] at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:135587:509:53:00.126在胡克。eval [as callAsync] (eval at create (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:33832:10),:6:1)[09:53:00.127]在AsyncQueue。_handleResult (/vercel/path0/node_modules/下/dist/编译/webpack/bundle5.js: 135557:21)09:53:00.127 at/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:135540:1109:53:00.127在阵列。(/vercel/path0/node_modules/下/dist/编译/webpack/bundle5.js: 59296:4)09:53:00.128 at runCallbacks (/vercel/path0/node_modules/next/dist/compiled/webpack/bundle5.js:20480:15)09:53:00.155错误:命令"npm run "以1
退出
对不起,如果格式使它难以阅读,我不太确定如何复制错误日志没有格式运行。
我所改变的一切都可以归结为添加一个使用NavBar, and Footer
组件的Layout
组件。然后,我修改了_app.js
文件,以使用所述布局:
import React from "react";
import App from "next/app";
import "tailwindcss/tailwind.css";
import Layout from "../components/Layout";
class MyApp extends App {
render() {
const { Component, pageProps, router } = this.props;
if (router.pathname.startsWith("/shop/")) { //router path check to include/exclude Layout e.g: paths starting with /shop
return (
<Layout>
<Component {...pageProps}></Component>
</Layout>
);
}
return <Component {...pageProps}></Component>;
}
}
export default MyApp;
任何关于这个错误的见解都是非常感激的!
不要从react模块中导入Component,它是一个保留关键字,用于扩展类
import React, { Component } from "react";
class SomeNavComponent extends Component {
而且,在我看来,问题似乎是与组件的命名有关,
const { Component, pageProps, router } = this.props;
没有改变任何东西,再次推到Vercel后错误没有弹出,所以它'修复';现在我想。