Instead of showing the 404 page, non-existing pages are pointing to Netlify functions
Bartmr opened this issue · comments
When using the default gatsby-plugin-netlify
and @netlify/plugin-gatsby
using the instructions on the README, all Not Found Urls are being redirected to this weird page that seems to be trying to load a Netlify Function. The page returns a 502 status and shows
{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, lstat '/var/task/.cache/data'","trace":["Error: ENOENT: no such file or directory, lstat '/var/task/.cache/data'"," at Object.lstatSync (fs.js:1119:3)"," at Object.lstatSync (/var/task/.netlify/functions-internal/__dsg/__dsg.js:466:38)"," at statFunc (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1172:106)"," at getStatsSync (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1173:23)"," at Object.checkPathsSync (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1211:37)"," at copySync2 (/var/task/.netlify/functions-internal/__dsg/__dsg.js:1311:42)"," at prepareFilesystem (/var/task/.netlify/functions-internal/__dsg/__dsg.js:2929:32)"," at getHandler (/var/task/.netlify/functions-internal/__dsg/__dsg.js:2954:3)"," at Object.<anonymous> (/var/task/.netlify/functions-internal/__dsg/__dsg.js:3002:45)"," at Module._compile (internal/modules/cjs/loader.js:1085:14)"]}
I am using the latest Gatsby v4 and the latest Netlify plugins, and only do calls to createPage
in gatsby-node
to create content pages. I have no SSR or DSG pages. Everything is generated into a static file.
During the Netlify build, this message caught my attention:
1:31:13 AM: ────────────────────────────────────────────────────────────────
1:31:13 AM: 3. @netlify/plugin-gatsby (onBuild event)
1:31:13 AM: ────────────────────────────────────────────────────────────────
1:31:13 AM:
1:31:13 AM: Netlify configuration property "redirects" value changed to [ { from: '/*', to: '/.netlify/functions/__dsg', status: 200 } ].
It seems that by default, gatsby creates a functions
directory inside .cache
, even when functions are not used
This in turn makes the condition in #
netlify-plugin-gatsby/plugin/src/index.ts
Line 64 in 44b11ad
always true
@Bartmr I have the same problem, did you find any workaround?
It looks like Gatsby has changed its behaviour there. I'm working on the plugin now so will have a fix in tjhe next few days. In the meantime a workaround if you're not using DSG or SSR would be to add the following to the end of static/_rewrites
:
/* /404.html 404
@Bartmr I have the same problem, did you find any workaround?
Yes, I'm currently deleting .cache/functions
after build
@Bartmr I have the same problem, did you find any workaround?
Yes, I'm currently deleting
.cache/functions
after build
Thanks that solved my problem, I added this to my netlify.toml
:
[build]
command = "gatsby build && rm -rf .cache/functions"
@Bartmr I have the same problem, did you find any workaround?
Yes, I'm currently deleting
.cache/functions
after buildThanks that solved my problem, I added this to my
netlify.toml
:[build] command = "gatsby build && rm -rf .cache/functions"
Thank you, this seems to have sorted it for me as well for now.
Instead of deleting the folder, you should now be able to set the environment variable NETLIFY_SKIP_GATSBY_FUNCTIONS
to true.