当我使用ts引用路径时
使用此
import * as fs from 'fs';
import * as path from 'path';
但是node index.ts
,出了点问题
import * as path from 'path';
^
SyntaxError: Unexpected token *
at Module._compile (internal/modules/cjs/loader.js:703:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:826:10)
at internal/main/run_main_module.js:17:11
node -version 12.0.0
答案 0 :(得分:0)
您需要在节点中使用ES模块才能使用ES 6导入。 https://blog.logrocket.com/es-modules-in-node-js-12-from-experimental-to-release/