0

I'm new to Gatsby, and I've been asked to add something to a Gatsby project, that isn't quite related to Gatsby. The dependency I had to add was not compatible with older versions of Gatsby, so I updated it to the latest version (^5.13.3). Thing is, when I ran gatsby develop the first time, I got an error that after looking into it, it resolved running export NODE_OPTIONS=--no-experimental-fetch, but after some changes, killing the execution (for other reasons) and running again gatsby develop, I started getting an error like this:

"gatsby-node.js" threw an error while running the onPreInit lifecycle:

Cannot access 'd' before initialization

   5 | import { rpcData } from "./src/hooks/useTenk"
   6 |
>  7 | export const onPreInit: GatsbyNode["onPreInit"] = async () => {
     |              ^
   8 |   const data = await rpcData()
   9 |   fs.writeFileSync(
  10 |     path.resolve('stale-data-from-build-time.json'),

and

"gatsby-node.js" threw an error while running the createPages lifecycle:

Cannot access 'u' before initialization

  13 | }
  14 |
> 15 | export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
     |              ^
  16 |   console.log(1, locales)
  17 |   locales.forEach(locale => {
  18 |     actions.createPage({

When running gatsby develop and going to localhost, I have 3 pages: "/404/", "/404.html" and "/". The site has a [locale].tsx file on src/templates/[locale].tsx and the createPages loads from there like this, but since it's failing, it is not loading.

export const createPages: GatsbyNode["createPages"] = async ({ actions }) => {
  console.log(1, locales)
  locales.forEach(locale => {
    actions.createPage({
      path: locale.id,
      component: path.resolve("src/templates/[locale].tsx"),
      context: { locale },
    })
  })
}

I find this error weird, since I'm not using a d or u variable in any place, and I wasn't able to find something online. Let me know if I can add some more code.

1 Answer 1

0

There is a bug with gatsby-node.ts. You’ll need to change it to .mjs and test if it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.