Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!