Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using TypeScript package using workspace in gatsby-node.ts : ReferenceError: Cannot access 'D' before initialization #38927

Open
2 tasks done
julianCast opened this issue Apr 9, 2024 · 0 comments
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby

Comments

@julianCast
Copy link

julianCast commented Apr 9, 2024

Preliminary Checks

Description

🟢 VALID: import { DISABLED_LOCALE_CODES } from "../constants";
🔴 ERROR (only in gatsby-node file): import { DISABLED_LOCALE_CODES } from "@pkgs-frontend/constants";

Trying to use custom package @pkgs-frontend/constants in pkg-pages/gatsby-node.ts will throw mentioned error. Using the package along the same package pkg-pages but within pages works fine.

import path from "node:path";

import { LOCALES } from "@pkgs-frontend/constants"; // This package would cause the error
import i18nIsoLanguages from "@cospired/i18n-iso-languages";
import i18nIsoCountries from "i18n-iso-countries";
import i18next from "i18next";
import i18nextFsBackend from "i18next-fs-backend";

import type { Actions, GatsbyNode, Page, Reporter } from "gatsby";
import type { Resource } from "i18next";
import type { SetRequired } from "type-fest";

import { REDIRECTS } from "./redirects";
 
console.log(LOCALES); // <-   ReferenceError: Cannot access 'D' before initialization

tsconfig.json of pkgs-frontend constants

{
  "extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
  "compilerOptions": {
    "outDir": "./dist",
    "declaration": true,
    "composite": true,
    "importsNotUsedAsValues": "remove"
  },
  "include": ["src/**/*.ts"]
}

Reproduction Link

NA

Steps to Reproduce

  1. Import a TS package into gatsby-node.ts
  2. Use the package
  3. Build and see the error
    ...

Expected Result

Successful build.

Actual Result

image

Environment

System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M1 Pro
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.17.0 - /private/var/folders/7t/x_27lndd5lz_qt50v0jfdygc0000gn/T/xfs-1900ff76/node
    Yarn: 3.8.1 - /private/var/folders/7t/x_27lndd5lz_qt50v0jfdygc0000gn/T/xfs-1900ff76/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
  Browsers:
    Chrome: 123.0.6312.107
    Edge: 123.0.2420.81
    Firefox: 118.0.1
    Safari: 16.1
  npmPackages:
    gatsby: ^5.11.0 => 5.11.0
    gatsby-plugin-google-tagmanager: ^5.11.0 => 5.11.0
    gatsby-plugin-image: ^3.11.0 => 3.11.0
    gatsby-plugin-manifest: ^5.11.0 => 5.11.0
    gatsby-plugin-material-ui: ^4.1.0 => 4.1.0
    gatsby-plugin-netlify: 5.1.1 => 5.1.1
    gatsby-plugin-nprogress: ^5.11.0 => 5.11.0
    gatsby-plugin-sharp: ^5.11.0 => 5.11.0
    gatsby-plugin-sitemap: ^6.11.0 => 6.11.0
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.32 => 1.1.32
    gatsby-source-filesystem: ^5.11.0 => 5.11.0
    gatsby-source-sanity: 7.9.1 => 7.9.1
    gatsby-transformer-sharp: ^5.11.0 => 5.11.0

Config Flags

No response

@julianCast julianCast added the type: bug An issue or pull request relating to a bug in Gatsby label Apr 9, 2024
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 9, 2024
@julianCast julianCast changed the title Error using TypeScript package from within a PNPM monorepo in gatsby-node.ts : ReferenceError: Cannot access 'D' before initialization Error using TypeScript package using workspace in gatsby-node.ts : ReferenceError: Cannot access 'D' before initialization Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

1 participant