In my Typescript project, I usually run it using "ts-node".
$ ts-node .\src\index.ts
it works =)
However, I wanted to compile it to Javascript, so I tried the following:
$ tsc
$ node .\src\index.js
Unfortunately, I encountered the following error:
(node:4392) UnhandledPromiseRejectionWarning: \event-monitor\src\models\Alarm.ts:1
(function (exports, require, module, __filename, __dirname) { import BaseEntity from "./BaseEntity";
^^^^^^^^^^
SyntaxError: Unexpected identifier
at new Script (vm.js:79:7)
at createScript (vm.js:251:10)
at Object.runInThisContext (vm.js:303:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
...
I find it puzzling that the project runs fine with 'ts-node' but encounters issues with TSC.
Here is an excerpt from my ts-config file:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
...
},
"include": ["src/**/*.ts", "tests/**/*.ts", "repoTest.ts"],
"exclude": ["node_modules"]
}
The modules I am utilizing include:
"lodash": "^4.17.11",
"mysql": "^2.17.1",
...
"typescript": "^3.0.3"