S
S
Shakir Darion2019-10-30 01:19:37
typescript
Shakir Darion, 2019-10-30 01:19:37

Terminal `node ./src/index.ts` SyntaxError?

import * as yargs from 'yargs';

const newYargs = yargs.argv;

console.log(newYargs.value);

running command in terminal node ./src/index.ts i get this error.
import * as yargs of 'yargs': SyntaxError: Cannot use import statement outside of module
What's the problem? How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
2
2CHEVSKII, 2019-10-30
@2chevskii

Compile the project. Well, it's generally, since you have a typescript file, I assume that you will use the features of the typescript.
And if specifically about ES6-style imports, then the --experimental-modules key and the .mjs extension, or the type:module field in package.json will solve the problem.

D
Dmitry Belyaev, 2019-10-30
@bingo347

install (can be globally)
https://www.npmjs.com/package/ts-node
and run from it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question