Link Search Menu Expand Document

window is not defined

nextjs + window is not defined

cause

  • window not available server side

fix

check for window

if (typeof window !== "undefined") {
  // browser code
}

use effet

use dynamic import

// pages/index.js

import dynamic from "next/dynamic";

const Scroll = dynamic(
  () => {
    return import("../components/Scroll");
  },
  { ssr: false }
);

export default function Home() {
  return (
    <div style=>
      <h1>Home</h1>
      <Scroll />
    </div>
  );
}

Cannot find module for page

  • causes
    • next dev is messing things up
> Build error occurred
Error: Cannot find module for page: /account/subscribe
    at pageNotFoundError (/Users/kevinlin/projects/dendronv2/dendron-landing/dendron-landing/node_modules/next/dist/next-server/server/require.js:1:384


Copyright © 2020 Thence LLC