1

Im trying to use the library bpmn.io in a local type script project in order to extend it.

So i try to import its components using the statement import {BpmnModeler, BpmnViewer} from 'bpmn-js'. The library apparently uses es6 modules internally to import and export stuff around.

When i try to run this code using ts-node <path/to/my/index.ts> (entry point of my typescript project), i get an unexpected token 'export' in the terminal, at the default export from the bpmn.io library.

Below is my tsconfig.json

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "lib": [
      "es2020"
    ],

    "allowJs": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "outDir": "./dist",
    "composite": true,
    "strict": true,
    "moduleResolution": "node",
    "rootDirs": [
      "."
    ],

    "esModuleInterop": true,
   
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "references": [],
  "watchOptions": {
    "fallbackPolling": "dynamicPriority",
    "excludeDirectories": [
      "**/node_modules",
      "build"
    ]
  }
}

I believe this happens because i have module: "commonjs" option set in the tsconfig.json above. But if i change it to module: "es6" then i must set the type="module" option in my package.json which results in unknonwn file extension .ts error. Kind of in a circle of problems here

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
BEvo
  • 357
  • 6
  • 18
  • 1
    "*unknonwn file extension .ts*" - but your package.json should reference the compiled .js files, not the typescript sources? – Bergi Jul 27 '21 at 15:45
  • 1
    when im using node, sure. I'm using ts-node though. – BEvo Jul 27 '21 at 15:52

1 Answers1

0

Did you try setting your target to ES5?

Check this answer:

unexpected token import/export - typescript

I was having the same issue but I fixed it.

LJD
  • 498
  • 4
  • 11