I have a .ts file in node js (latest version of node.js for 07.10.19) app with importing node-module without default export. I use this construction: import { Class } from 'abc';
When i run the code, i have this error: Cannot use import statement outside a module
.
In the network i see many solutions for this problem (for .js), but it not helps to me, maybe because i have typescript file. Here's my code:
import { Class } from 'abc';
module.exports = { ...
execute(a : Class ,args : Array<string>){ ...
Here's my tsconfig.json:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"strict": true
}
}
import
statement the first line in your file? – Evertrequire
vsimport
) you use. Just to give you a sense of how complicated this is, Node has some documentation aboutimport
vsrequire
and how to make them work together. – Jeff Bowmanmodule.exports
syntax, you're probably not in an ES6 module. – Bergiexecute(a : abc.Class...
– Zerumi