最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

打字稿的NodeJS:变量没有定义,使用单独的文件内部参考路径

IT培训 admin 8浏览 0评论

打字稿/的NodeJS:变量没有定义,使用单独的文件内部参考路径

我一直在测试打字稿与节点,一切进行得很顺利,直到我试图分裂出来这些。

我是被迫使用模块?

我有2个文件,其中有一个参考路径hellofile.tst app.ts

/// <reference path="hellofile.ts" />
var testme = new Hello()
console.log(testme.testMe());

和包含hellofile.ts

class Hello {
    testMe():string {
        return "hello";
    }
}

现在运行的程序(我使用webstorm),我收到以下错误。

/usr/local/bin/node app.js

/

Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2
var testme = new Hello();
                 ^
ReferenceError: Hello is not defined
    at Object.<anonymous> (/Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Process finished with exit code 8
回答如下:

您不必使用模块。你可以用--out标志编译

但随着CommonJS的外部模块,强烈建议,如果瞄准的NodeJS:http://m.youtube/watch?v=KDrWLMUY0R0

打字稿/的NodeJS:变量没有定义,使用单独的文件内部参考路径

我一直在测试打字稿与节点,一切进行得很顺利,直到我试图分裂出来这些。

我是被迫使用模块?

我有2个文件,其中有一个参考路径hellofile.tst app.ts

/// <reference path="hellofile.ts" />
var testme = new Hello()
console.log(testme.testMe());

和包含hellofile.ts

class Hello {
    testMe():string {
        return "hello";
    }
}

现在运行的程序(我使用webstorm),我收到以下错误。

/usr/local/bin/node app.js

/

Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2
var testme = new Hello();
                 ^
ReferenceError: Hello is not defined
    at Object.<anonymous> (/Users/tst/WebstormProjects/NodeJsWithTypescript/app.js:2:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

Process finished with exit code 8
回答如下:

您不必使用模块。你可以用--out标志编译

但随着CommonJS的外部模块,强烈建议,如果瞄准的NodeJS:http://m.youtube/watch?v=KDrWLMUY0R0

发布评论

评论列表 (0)

  1. 暂无评论