1

I am trying to run apollo-server and the code I have written is in TypeScript.

My code folder contains a tsconfig.json which looks like this:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": [
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": [
    "server"
  ]
}

The command I am running is below:

$ npx ts-node ./server/index.ts

If I remove the tsconfig.json (which of course I can't do), the command above works fine. I am not sure which configuration is actually causing the problem.

2
  • did you found a solution? Commented Jul 19, 2020 at 14:01
  • @Pablo For now I have temporarily removed the module option which seems to work. Commented Jul 20, 2020 at 9:08

1 Answer 1

1

the setting you are searching is "module": "commonjs". As ts-node is executing your code in the nodejs environment you have to use its module system. If you need your config as default for your project you can create a second tsconfig tsconfig.node.json and target it with ts-node --project <tsconfig.json>

tsconfig.node.json:

{
  "extends": "./",
  "compilerOptions": {
    "module": "commonjs",
  },
}
Sign up to request clarification or add additional context in comments.

2 Comments

I tried changing module option to commonjs. It didn't work. I have es6 style imports in the code. It throws an error for that.
I will give this second approach of providing a separate tsconfig.json file a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.