0

Asked to make a laboratory and an import error occurred

//dao.ts file

    import * as fs from "fs";
    const file = fs.readFileSync("foo.txt", "utf8");
    console.log(file);

I write "node dao.ts" in console and i have error:

    import * as fs from "fs";
^^^^^^
SyntaxError: Cannot use import statement outside a module
Timur
  • 1
  • 1
    try tsc nao.ts and later node dao.js – 0210vidit Oct 06 '21 at 08:17
  • @0210vidit sanks, but when i used any import i have error ** ``` import * as mongo from "mongodb"; ^^^^^^ SyntaxError: Cannot use import statement outside a module ``` ** – Timur Oct 06 '21 at 08:25

0 Answers0