Apolo graphql server v4 setup using Typescript Not working with module exports

Hi , i recently trying to graphql apolo v4 with typescript , i followed the instructions provided on the website.
My resolvers and typeDefs were in seperate files , i am importing them as
import {resolvers} from ‘./resolvers’
i am using typescript , but it gies error that ,
“dist/resolvers” are not define. is there any sollution for this .

1 Like

Can you share a reproduction or the repository where you’re running into this error?

If you’re using ES Modules in TypeScript your file paths probably need to include a .js extension, so your import would be from ./resolvers.js - the js is not a typo. You can see we do this in the Apollo Server repo as well as an example.

Thanks for response:
github repo: GitHub - syedslegend786/chat-app-graphql-backend

i am important folder imports (“/graphql”===“/graphql/index.ts”) in my root file , but it does’nt convert into graphq/index.js in the dist folder,
like we do in react js imports.

one more thing ,
how to setup that , whenever i change my file , then these changes also applied to my app.

Thanks for sharing the repo. If you convert all of your file imports to have the .js extension (even the folder / index imports) then the errors go away.

It sounds like you’re interested in a tool like nodemon. You’ll want to run TypeScript in watch mode with the -w flag, and have nodemon watch the dist/index.js file for changes.

1 Like