Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda