铸造时的打字稿错误

时间:2016-10-06 09:21:44

标签: typescript webpack karma-runner

我正在运行一个运行Jasmine和Karma的种子项目。 一切都设置正确。

Webpack启动应用程序" npm start" 但是,当我跑步" npm test" Webpack查看.ts文件,然后加载.spec.ts文件。 从种子项目

运行此代码时出现错误
bundle is now VALID.
[32m06 10 2016 10:16:42.660:INFO [karma]: 
[39mKarma v0.13.22 server started at http://localhost:9876/

[32m06 10 2016 10:16:42.664:INFO [launcher]: 
[39mStarting browser PhantomJS
[32m06 10 2016 10:16:44.259:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: 
[39mConnected on socket /#YRouUOeCLSlLTu_KAAAA with id 23215732
PhantomJS 2.1.1 (Windows 7 0.0.0)

ERROR
  SyntaxError: Unexpected token '<'
  at C:/Development/ScratchApp/ScratchApp/src/test.ts:4

PhantomJS 2.1.1(Windows 7 0.0.0)

错误是意外的令牌&#39;&lt;&#39; 在以下test.ts文件中

// this file is only being used by karma
require('phantomjs-polyfill')

requireAll((<any>require).context("./", true, /spec.ts$/));
function requireAll(r: any): any {
    r.keys().forEach(r);
}

有人可以看到这种语法错误吗?

1 个答案:

答案 0 :(得分:1)

这个问题的重要部分是:

at C:/Development/ScratchApp/ScratchApp/src/test.ts:4

这就是为什么您会收到&#39;&lt;&#;;的意外标记,因为您的TypeScript文件在<any>开始的行上有requireAll。 JavaScript不期望找到类型注释,这就是为什么它们在编译期间都被擦除的原因。

更新运行时代码以使用编译文件:

C:/Development/ScratchApp/ScratchApp/src/test.js