1

I have the following code in typescript in main.ts:

import { of } from "rxjs";
import { map } from 'rxjs/operators';

class Main {
  public process() {
    console.log("Hello world!!!");
    of(1, 2, 3).pipe(map(x => x * 2));
  }
}

let main: Main = new Main(); main.process();

When I run node main.ts I receive:

main.ts:1
import { of } from "rxjs";
       ^

SyntaxError: Unexpected token {
←[90m    at Module._compile (internal/modules/cjs/loader.js:718:23)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:641:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:556:12)←[39m
←[90m    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)←[39m
←[90m    at internal/main/run_main_module.js:17:11←[39m
Mihai Catan
  • 106
  • 9
  • 2
    Does this answer your question? [How to run TypeScript files from command line?](https://stackoverflow.com/questions/33535879/how-to-run-typescript-files-from-command-line) – Andrew Nolan Feb 21 '20 at 13:28
  • The problem is with the error generated not on how to start ts file with nodemon – Mihai Catan Feb 21 '20 at 15:26
  • You are trying to run a .ts file, which is not .js. You need to compile your .ts file to js to run in node. Which is what the other question has the answer for. – Andrew Nolan Feb 21 '20 at 15:46
  • Ok, I see. I thought the problem I have is not related to ts file and only some error I could not find. I fixed this. Thanks for the help. – Mihai Catan Feb 21 '20 at 15:50

0 Answers0