【发布时间】:2016-10-06 09:21:44
【问题描述】:
我正在运行一个运行 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)
错误是 Unexpected token '
// 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);
}
有人能看到这个语法错误吗?
【问题讨论】:
-
似乎您正在尝试运行打字稿代码。您应该首先将 typescript 代码编译成 javascript 代码,然后运行它。
-
是的,你是对的。由于源代码控制丢失了映射文件(和定义),问题比我在这里发布的要复杂得多。由于某种奇怪的原因,WebPack 在构建服务器上查看了错误的源
标签: typescript webpack karma-runner