Gatsby 4 - Runtime.ImportModuleError on 404 pages

Hello everyone,

My Netlify site name is thirdfort-marketing-internal

I just upgraded to Gatsby 4 (and integrated Prismic headless CMS as part of the process) but unfortunately I’m getting a bug when previewing my Pull Request.

The build is successful and existing pages work great, but if I go to a non-existent page (Eg I get the following message

"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module '/var/task/.cache/page-ssr'\nRequire stack:\n- /var/task/.netlify/functions-internal/__dsg/__dsg.js\n- /var/task/__dsg.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js",
"trace": [
"Runtime.ImportModuleError: Error: Cannot find module '/var/task/.cache/page-ssr'",
"Require stack:",
"- /var/task/.netlify/functions-internal/__dsg/__dsg.js",
"- /var/task/__dsg.js",
"- /var/runtime/UserFunction.js",
"- /var/runtime/index.js",
"    at _loadUserApp (/var/runtime/UserFunction.js:100:13)",
"    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)",
"    at Object.<anonymous> (/var/runtime/index.js:43:30)",
"    at Module._compile (internal/modules/cjs/loader.js:1072:14)",
"    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)",
"    at Module.load (internal/modules/cjs/loader.js:937:32)",
"    at Function.Module._load (internal/modules/cjs/loader.js:778:12)",
"    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)",
"    at internal/main/run_main_module.js:17:47"

The annoying thing is that I’m not using any functions or DSG pages. It seems that the error is coming from there. Is there a way to fix this or disable the functions altogether?

I’m using the correct ENV for my builds so it supports Gatsby 4



Goal is to:

  • get the 404 page if I go to a page that doesn’t exist
  • be able to preview Prismic pages that are in draft (not live yet).

Anything that could help will be amazing - I’ve tried pretty much anything I can think of but there isn’t much info online about it.



Just wanted to check if there are any updates on this? At the moment, this is a big blocker to me merging the branch so I might need to do downgrade to Gatsby 3 before doing so.


Hey @kb1995,

Since you’re not using any DSG, I’m assuming it’s a fully static export? In that case, would it be possible for you to try uninstall the build plugin auto-installed by Netlify and give it a try?


Where can I find the build plugin which is auto installed by Netlify?

The only plugin which is currently present is the “Essential Gatsby” plugin.

@hrishikesh Update:

I disabled the Essential Gatsby plugin, and that seems to have fixed the problem.

However, my build times now take a lot longer and have some of these warning messages:

5:39:08 PM: warning Query takes too long:
5:39:08 PM: File path: /opt/build/repo/src/pages/estate-agents.tsx
5:39:08 PM: URL path: /estate-agents/
5:39:08 PM: warning Query takes too long:
5:39:08 PM: File path: /opt/build/repo/src/pages/for-lawyers.tsx
5:39:08 PM: URL path: /for-lawyers/
5:39:08 PM: warning Query takes too long:
5:39:08 PM: File path: /opt/build/repo/src/pages/index.tsx
5:39:08 PM: URL path: /
5:39:08 PM: warning Query takes too long:
5:39:08 PM: File path: /opt/build/repo/src/pages/partnerships.tsx
5:39:08 PM: URL path: /partnerships/

I guess we can’t do anything about that until the Essential Plugin supports Gatsby 4?

1 Like

Well, it’s good to know that the 404 page’s errors have been fixed. I would have assumed that Essential Gatsby Plugin would not change anything for purely static websites.

Could you try the Beta version, if you haven’t already: GitHub - netlify/netlify-plugin-gatsby: A build plugin to integrate Gatsby seamlessly with Netlify?

Hey, I had the beta version installed. So that’s probably something to report over to the team responsible for the plugin

Alright then, I’ll discuss this with the devs and get back to you with an update.

Hey @kb1995,

Sorry for the delay here, it appears to be a bug and the team is looking into it.

Meanwhile, the devs said that since you’re not using DSG, you should be fine with the non-beta version of the plugin as that’s not supposed to handle DSG.

Would you please give that a try?

1 Like

I had this exact issue. Not using DSG, but had followed instructions here:

Only difference is I had to use

npm install -D @netlify/plugin-gatsby@^2.0.0-zz-beta.0

in order to install the beta package. (just picked the most likely one)

But still got the same error as OP until I downgraded to the non-beta 1.3.0 version. And now 404 pages deliver correctly. Woohoo!

1 Like

Any updates on this from the team? Not having 404 pages could hurt SEO, and disabling SSR (by downgrading to @netlify/plugin-gatsby v1.0.3) could hurt too.

In the mean-time I’m using this solution: Instead of showing the 404 page, non-existing pages are pointing to Netlify functions · Issue #219 · netlify/netlify-plugin-gatsby · GitHub

Hey @abo,

I believe this will be fixed in a future version of the plugins.

Any word on this as it’s 2 months since the last comment?

I’ve got multiple sites I’m looking to launch fairly soon and this is the 404 error scenario:

Hey @gideongoddard,

We’re not seeing that issue actively occur anymore. Could you share your site name so we can check for the issue?

I can confirm the issue is still occurring for me aswell using Gatsby 4.11.1 . You can check out my site, too:

This site is still experiencing the issue:

Another had the issue but it’s been resolved by changing the Essential Gatsby plugin version to v1.0.3:

Hey there folks!

Thanks for chiming in. @gideongoddard, did you try changing the Essential Gatsby plugin version on both sites?

If this error is still occurring, can you both share your most recent deploy log? @HelloUniverse

Hi @hillary

I didn’t try downgrading the first of those sites but I’ve just seen that there’s been a v3 release which I’ve upgraded to and now don’t have the issue on that site either.

1 Like

Hello @hillary,

indeed switching to the new V3 Gatsby Build Plugin solved the Issue for me aswell. Thank you!

1 Like

Thank you both for reporting back and letting us know. Glad everything is working now. Happy building :rocket:

1 Like