【问题标题】:I have just the Started the learning the Type Script ans getting the below error.please help on this and what could be the mistake?我刚刚开始学习打字稿并收到以下错误。请对此提供帮助,可能是什么错误?
【发布时间】:2018-03-04 02:28:00
【问题描述】:
var n:string = "mary";

D:\Angular\TS>node Untitled_2.ts

D:\Angular\TS\Untitled_2.ts:1(function (exports, require, module, 
__filename, __dirname) { var n:string = "mary";
                                                               ^

SyntaxError: Unexpected token :
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3

【问题讨论】:

  • 如果没有看到导致错误的代码就很难判断。我猜你需要在函数中移动代码。
  • 你的代码 sn-p 无法理解

标签: node.js angular typescript


【解决方案1】:

您的问题是您必须先编译 Typescript 代码,然后才能使用 node.js 运行它。你可以通过两种方式做到这一点。

  1. 运行tsc Untitled_2.ts,然后运行node Untitled_2.js(假设没有改变输出路径的额外配置)

  2. 安装ts-node并运行ts-node Untitled_2.ts

您可能需要在上述命令前加上 npm runyarn 前缀才能将命令添加到您的路径中。

【讨论】:

    猜你喜欢
    • 2023-01-20
    • 2020-02-22
    • 2016-02-25
    • 1970-01-01
    • 2017-05-10
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多