Next.js: Upgrading from 9.2.1 --> 9.3.5 "Error: Cannot find module 'next/dist/next-server/lib/fid.js'"

Created on 15 Apr 2020  路  20Comments  路  Source: vercel/next.js

Trying to upgrade from 9.2.1 to latest stable release (9.3.5).
Node Version: 10.16

Compiles successfully in terminal, but when opening localhost:port, I'm getting the following:

[ ready ] compiled successfully - ready on http://localhost:7778
{ Error: Cannot find module 'next/dist/next-server/lib/fid.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:690:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.../next-server/lib/fid (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:136:18)
    at __webpack_require__ (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:23:31)     
    at Object../node_modules/next/dist/pages/_document.js (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:192:35)
    at __webpack_require__ (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:23:31)     
    at Object../node_modules/next/document.js (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:878:18)
    at __webpack_require__ (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:23:31)     
    at Module../pages/_document.js (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:895:71)
    at __webpack_require__ (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:23:31)     
    at Object.1 (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:996:18)
    at __webpack_require__ (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:23:31)     
    at module.exports.../../node_modules/common/src/assets/image/favicon-32.png.module.exports (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:91:18)
    at Object.<anonymous> (C:\Users\Wade\Documents\GitHub\myodesign\dist\functions\next\server\static\development\pages\_document.js:94:10) code: 'MODULE_NOT_FOUND' }

next.config

const withPlugins = require("next-compose-plugins");
const withTM = require("next-transpile-modules");
const withOptimizedImages = require("next-optimized-images");
const withFonts = require("next-fonts");
const withCSS = require("@zeit/next-css");
module.exports = {
  webpack: (config, { isServer }) => {
    // Fixes npm packages that depend on `fs` module
    if (!isServer) {
      config.node = {
        fs: "empty"
      };
    }

    return config;
  }
};

module.exports = withPlugins(
  [
    [
      withTM,
      {
        transpileModules: ["reusecore", "common"]
      }
    ],
    [
      withOptimizedImages,
      {
        mozjpeg: {
          quality: 90
        },
        webp: {
          preset: "default",
          quality: 90
        }
      }
    ],
    withFonts,
    withCSS
  ],
  {
    distDir: "../../dist/functions/next"
  }
);

_document.js

import Document, { Html, Head, Main, NextScript } from "next/document";
import { ServerStyleSheet } from "styled-components";
import FavIcon from "common/src/assets/image/favicon-32.png";

export default class CustomDocument extends Document {
  static async getInitialProps(ctx) {
    const sheet = new ServerStyleSheet();
    const originalRenderPage = ctx.renderPage;

    try {
      ctx.renderPage = () =>
        originalRenderPage({
          enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
        });

      const initialProps = await Document.getInitialProps(ctx);
      return {
        ...initialProps,
        styles: (
          <>
            {initialProps.styles}
            {sheet.getStyleElement()}
          </>
        )
      };
    } finally {
      sheet.seal();
    }
  }
  render() {
    return (
      <html lang="en">
        <Head>
          <link rel="shortcut icon" type="image/x-icon" href={FavIcon} />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </html>
    );
  }
}

Most helpful comment

same is happening in my app

All 20 comments

same is happening to me

same is happening in my app

same happening here...

same here

I just want to let everyone know that I managed to solve the issue by going to the canary build (10). Give it a try. It's not a real solution or explanation, but it seems like the Vercel team is just ignoring this.

Update : Vercel is on it :) Or, as best they can without a repo.

@hatchli thank you! I'll try this

but it seems like the Vercel team is just ignoring this.

Not ignoring it. The issue was not closed and currently has 2 馃憤 from other people. Note that there are 421 open issue as of currently.

You did not follow the issue template btw. It asks for a clear and concise reproduction, what was provided are 2 files.

A rollback to 9.3.4 worked for me

but it seems like the Vercel team is just ignoring this.

Not ignoring it. The issue was not closed and currently has 2 from other people. Note that there are 421 open issue as of currently.

You did not follow the issue template btw. It asks for a clear and concise reproduction, what was provided are 2 files.

Fair enough! I don't have the ability to open my repo, nor the resources to make a new one atm. Glad to hear this was on the radar though :)

My site suddenly got this issue, been on v9.3.6 for 10 days with no issue. Suddenly it happened :/

Seems to works well on v9.4.0 too

I'm getting this error on v9.4.0 and I downloaded to v9.3.4 and it's still happening.

UPDATE: I ended up throwing away my repo and starting from scratch.

me too :(. worked well before but now it's happing

Closing as no reproduction was provided. Please upgrade to 9.4 and let us know if it still happens.

Happened to me too. Downgrading to 9.3.6 fixed it.

Can you upgrade to 9.4.1?

For those who have the same problem, I solve it by removing and reinstalling next using yarn. I've used the 9.3.5 version.

The downgrade failed once for me, which I later found due to yarn.lock issue.

Hope this helps.

I saw this when upgrading from 9.3.6 to 9.5.3 but it was solved by removing the .next directory which was generated by the old version.

Here I solved by doing
ctrl + shift + p
> TypeScript: Restart TS server

Delete node_modules folder and run npm i again, worked for me! :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knipferrc picture knipferrc  路  3Comments

lixiaoyan picture lixiaoyan  路  3Comments

havefive picture havefive  路  3Comments

renatorib picture renatorib  路  3Comments

sospedra picture sospedra  路  3Comments