scott vaughn
scott vaughn

Reputation: 56

TS2306 is not a module error on typescript file

So I'm getting this error for my typescript file. I don't understand why it's not working. From what I understand this is what you need to do to export a class. But I keep getting an error that my file is not a module and can't be imported.

Error

TS2306 is not a module error on typescript file
export default class GridApi{
    Hello(): string {
        return "Hello"
    }
}

Also here is my tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "CommonJS",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": false,
    "jsx": "react"
  },
  "exclude": [
    "node_modules",
    "./node_modules",
    "./node_modules/*"
  ]
}

Upvotes: 3

Views: 9265

Answers (1)

Aplet123
Aplet123

Reputation: 35482

Your module setting is set to CommonJS, which is not what you want. CommonJS modules use the require syntax, but you use import/export. You should instead use ES6 modules:

"module": "ES6",

Read more about TSC options here.

Upvotes: 4

Related Questions