0

this my code

import * as yargs from 'yargs';

const newYargs = yargs.argv;

console.log(newYargs.value);

run the command in the terminal node ./src/index.ts i get this error

import * as yargs from 'yargs': SyntaxError: Cannot use import statement outside a module

What is the problem? How to fix it?

Edgar
  • 6,022
  • 8
  • 33
  • 66

1 Answers1

0

node does not understand TypeScript. It only understands JavaScript.

If you want to run TypeScript directly, use ts-node.

unional
  • 14,651
  • 5
  • 32
  • 56
  • I installed locally ts-node.When I run ts-node `./src / index.ts ` I get an error `ts-node: Unable to load file C: \ Users \ Rich ... ts-node.ps1, because script execution is disabled in   this system` – Edgar Oct 30 '19 at 08:36