0

i am trying to import a commonjs module into my existing typescript project with type: module. I have these files:

// server.cts module.exports = "hello"

//index.ts import * as server from './server.cjs';

//tsconfig.json `{ "compilerOptions": { "target": "ES5",
"module": "ES2015",

"outDir": "dist", 
"sourceMap": true,
"esModuleInterop": true,           

}, "include": ["src/**/*"], }`

When i compile and run it compiles the server.cts to; module.exports = "suck"; export {}; //# sourceMappingURL=cllientServer.cjs.map

and gives the error: export {}; SyntaxError: Unexpected token 'export'.

This module stuff is really confusing at times

imported cjs with server exports

Damian
  • 1
  • 1
  • probably a duplicate of https://stackoverflow.com/questions/38296667/getting-unexpected-token-export "type":"module" in package.json probably solves problem – YAMM Jan 22 '23 at 13:29

0 Answers0