Cannot use import syntax with Typescript + babel + node SyntaxError: Cannot use import statement outside a module

Viewed 142

I'm trying to use import syntax in my project that trying to use graphql + node + babel + express + typescript. For example when I try to use apollo-client-express package that error shows up. I know typescript has own import syntax like *. The real thing is I cannot address the problem, is this causing from babel or typescript configs or anything else? here is my

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "moduleResolution": "node",
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2018",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./src",
    "incremental": true,
    "skipLibCheck": true,
    "esModuleInterop": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "dist",
    "*.js"
  ]
}

.babelrc:

{ "presets": ["@babel/preset-env"] }

0 Answers
Related