Error using TypeScript package using workspace in gatsby-node.ts : ReferenceError: Cannot access 'D' before initialization
julianCast opened this issue · 0 comments
julianCast commented
Preliminary Checks
- This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
- This issue is not a question, feature request, RFC, or anything other than a bug report directly related to Gatsby. Please post those things in GitHub Discussions: https://github.com/gatsbyjs/gatsby/discussions
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
- Import a TS package into gatsby-node.ts
- Use the package
- Build and see the error
...
Expected Result
Successful build.
Actual Result
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