Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
Can I call a TypeScript function from `gatsby-node.js` file?

My gatsby-node.js file is becoming huge, so I am abstracting it out in different files. However, I would like to use Typescript for the helper files.

I tried 2 things

  1. First, I created a function inside a Javascript file (helper.js) and called it from gatsby-node.js file. It worked fine.
  2. Then, I renamed the file extension to helper.ts, but I see failures in gatsby develop command
Error: Cannot find module './src/generators/usda/helper.ts'
  Require stack:
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/gatsby-node.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/bootstrap/load-plugins/load.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/bootstrap/load-config-and-plugins.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/services/initialize.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/services/index.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/state-machines/develop/services.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/state-machines/develop/index.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/node_modules/gatsby/dist/commands/develop-process.js
  - /Users/hhimanshu/code/prsnl/ts/forkfacts/.cache/tmp-18033-PnVyC3Y4PhuY

  - loader.js:889 Function.Module._resolveFilename
    internal/modules/cjs/loader.js:889:15

  - loader.js:745 Function.Module._load
    internal/modules/cjs/loader.js:745:27

  - loader.js:961 Module.require
    internal/modules/cjs/loader.js:961:19

  - v8-compile-cache.js:159 require
    [forkfacts]/[v8-compile-cache]/v8-compile-cache.js:159:20

  - gatsby-node.js:7 Object.<anonymous>
    /Users/hhimanshu/code/prsnl/ts/forkfacts/gatsby-node.js:7:55

  - v8-compile-cache.js:192 Module._compile
    [forkfacts]/[v8-compile-cache]/v8-compile-cache.js:192:30

  - loader.js:1101 Object.Module._extensions..js
    internal/modules/cjs/loader.js:1101:10

  - loader.js:937 Module.load
    internal/modules/cjs/loader.js:937:32

  - loader.js:778 Function.Module._load
    internal/modules/cjs/loader.js:778:12

  - loader.js:961 Module.require
    internal/modules/cjs/loader.js:961:19

  - v8-compile-cache.js:159 require
    [forkfacts]/[v8-compile-cache]/v8-compile-cache.js:159:20

  - resolve-module-exports.ts:197 resolveModuleExports
    [forkfacts]/[gatsby]/src/bootstrap/resolve-module-exports.ts:197:26

  - validate.ts:349 forEach
    [forkfacts]/[gatsby]/src/bootstrap/load-plugins/validate.ts:349:31

Is it possible to leverage TypeScript to write functions and call them from gatsby-node.js?

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Short answer - no, Long answer, yes - if you have the correct setup. Typescript is a superset of javascript, which means - typescript needs to be "transpiled" into javascript first before it can be executed by any javascript engine (there is no such thing as a "typescript engine")

There are many projects out there to achieve this like babel, SWC or ESBuild. But as you already mentioned gatsby, just have a look into a guide like this:

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-gatsby-project-with-typescript

Or just google "transpile typescript gatsby.js" or something like this :)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda