如何使用Karma-Webpack使用Node Typescripttypes
我已经configuration了Webpack来在Karma中传输我的TS文件。 我还包括Node和CoreJStypes。 但是,当我尝试运行我的testing,我得到…
ERROR in ./test/karma/test.bundle.ts (18,30): error TS2339: Property 'context' does not exist on type 'NodeRequire'.
我尝试使用npm install --save-dev @types/webpack-env
,但是这给我更多的错误。
ERROR in /.../node_modules/@types/webpack-env/index.d.ts (183,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'RequireFunction'. ERROR in /.../node_modules/@types/webpack-env/index.d.ts (232,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'module' must be of type 'NodeModule', but here has type 'Module'. ERROR in ./test/karma/test.bundle.ts (18,30): error TS2339: Property 'context' does not exist on type 'NodeRequire'.
我的噶configuration看起来像这样…
var webpack = require("webpack"); module.exports = function(config) { var webpackConfig = require("../../webpack.config"); // TODO: Can we get rid on this? // We need to remove entry points and plugins webpackConfig.plugins = [ // IMPORTANT!!!! Without this source maps fail to show up. new webpack.SourceMapDevToolPlugin({ filename: null, // if no value is provided the sourcemap is inlined test: /\.(ts|js)($|\?)/i // process .js and .ts files only }) ]; //This is used to remap can access (Based on https://github.com/sshev/karma-remap-coverage) webpackConfig.ts = { compilerOptions: { inlineSourceMap: true, sourceMap: false } }; webpackConfig.module.postLoaders = [ { test: /^((?!\.spec\.ts).)*.ts$/, exclude: /(node_modules|bower_components)/, loader: 'istanbul-instrumenter' } ]; webpackConfig.entry = {}; var configuration = { autoWatch: true, basePath: "", browsers: ["Chrome"], colors: true, concurrency: Infinity, coverageReporter: { type: 'in-memory' }, exclude: [ "node_modules" ], files: [ { pattern: "./test.bundle.ts", watched: true }, ], frameworks: ["jasmine"], htmlReporter: { outputFile: "../../reports/units.html" }, logLevel: config.LOG_INFO, port: 9876, preprocessors: { "./test.bundle.ts": ["webpack", "sourcemap" ], }, remapCoverageReporter: { "text-summary": null, html: "./reports/coverage/html" }, reporters: ["progress", "coverage", "remap-coverage", "html"], singleRun: false, webpack: webpackConfig, webpackMiddleware: { stats: "errors-only"} }; config.set(configuration); };
版本
webpack 1.14.0,节点v6.9.2,Typescript 2.1.4
- MSBuild是否需要在Angular2的依赖项(在node_modules中)中传输.ts文件以使Angular2正常工作?
- Typescript:属性“已解码”在types请求中不存在
- TS2304:无法在节点5.1.0,typescript 1.6.2,webstorm 11中find名称“Map”
- 如何在npm本地安装和运行Typescript?
- 打字稿错误:TS2304:找不到名称'$'
- TypeScript编译器很慢(6-10s)
- 合并名称空间和variables的声明
- 当“不要做”不是一个选项时,如何将Typescript命名空间与外部模块混合在一起
- 为什么在打字稿中声明一个全局的`name`variables,我可以避免使用它吗?