【发布时间】:2019-10-26 01:02:47
【问题描述】:
我正在尝试使用“node main.js”运行我的程序,但是,它不断出现错误“SyntaxError: Unexpected token {”
D:\Visual Studio Code Projects\ts-hello>node main.js
D:\Visual Studio Code Projects\ts-hello\main.js:1
import { LikeComponent } from './like.component';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
我尝试将 tsconfig.json 文件更改为“module”:“commonjs”,但是,这不起作用。我什至卸载并重新安装了节点并从头开始。
import{LikeComponent} from './like.component';
let component = new LikeComponent(10, true);
component.onClick();
console.log(`likesCount: ${component.likesCount}, isSelected: ${component.isSelected}`);
它应该正确地将程序输出到命令提示符。
【问题讨论】:
-
在
tsconfig.json中使用编译器选项"module": "commonjs"。然后再次编译。 -
您能否澄清一下您所说的编译器选项是什么意思?我已经进入配置文件并将模块更改为“模块”:“commonjs”,
标签: javascript typescript ecmascript-6