microsoft / TypeScript-Node-Starter

A reference example for TypeScript and Node with a detailed README describing how to use the two together.
MIT License
11.37k stars 2.78k forks source link

Cannot use import statement outside a module #256

Open aryeh-luwfy opened 4 years ago

aryeh-luwfy commented 4 years ago

compiling error in file inside folder in src directory

[Node] SyntaxError: Cannot use import statement outside a module
[Node]     at Module._compile (internal/modules/cjs/loader.js:892:18)
[Node]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
[Node]     at Module.load (internal/modules/cjs/loader.js:812:32)
[Node]     at Function.Module._load (internal/modules/cjs/loader.js:724:14)
[Node]     at Module.require (internal/modules/cjs/loader.js:849:19)
[Node]     at require (internal/modules/cjs/helpers.js:74:18)
lopesboa commented 4 years ago

I don't know if is to late to help, can you check your tsconfig file if you set the right specification on target & module.

"target":  "ES VERSION THAT YOU ARE CURRENT USING"  /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */

"module":  "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */