我有一个项目,它用jest和ts-jest运行名为"*.test.ts“的测试文件。这很好,但是当我启动webpack时,我得到了测试文件的错误:
ERROR in /some/path/note.test.ts
(27,3): error TS2304: Cannot find name '如何修复webpack配置,使其完全忽略测试文件?
下面是webpack的配置:
const path = require ( 'path' )
module.exports =
{ entry: './src/boot.tsx'
, node:
{ __dirname: false
}
, output:
{ path: path.resolve ( __dirname, 'app', 'build' )
, filename: 'app.js'
, publicPath: '/live-reload/'
}
, devtool: 'source-map'
, resolve:
{ extensions: ['', '.js', '.ts', '.tsx']
}
, module:
{ loaders:
[ { test: /\.tsx?$/
, exclude: /node_modules/
, loader: 'ts-loader'
}
]
}
}编辑
我使用测试函数来记录看到的文件,测试文件没有出现在那里,所以问题不是出在webpack包含错误的文件上,而是出在typescript行为不当上(因为测试在jest中工作得很好)。
发布于 2017-07-02 14:39:49
我最终也解决了这个问题,但采用了一种不同的方式,即将以下设置添加到我的.tsconfig文件中:
"include": [
"./lib/**/*"
],
"exclude": [
"./lib/__tests__"
]不知道为什么行动和公司不提这件事。也许他们的.tslint文件中已经有了这些设置(例如,因为他们的项目是从另一个项目生成或派生的)。
但看起来TypeScript (至少在2.3.2版本中)关注这些设置,而忽略了webconfig.config.js中的等效设置。
发布于 2016-12-20 17:42:29
您可以为加载器test属性指定函数而不是正则表达式;这可以使您获得更多的控制。
test: function (modulePath) {
return modulePath.endsWith('.ts') && !modulePath.endsWith('test.ts');
}发布于 2016-12-20 23:36:15
找到了。我的“ts-loader”版本落后了,不知何故无法正确处理已安装的@types。
经验法则:打包、构建、转换问题:升级开发依赖。
https://stackoverflow.com/questions/41238711
复制相似问题