在用ts和react的項目中進行webpack編譯的時候,會出現如下報錯:
The 'files' list in config file 'tsconfig.json' is empty Module build failed (from ../node_modules/ts-loader/index.js): Error: error while parsing tsconfig.json
我的版本號如下:
"ts-loader": "^5.3.1", "typescript": "^3.2.1", "webpack": "^4.27.1"
經過查詢驗證,解決方案如下:
在ts-loader的配置項中指定ts配置文件的絕對路徑即可。
原代碼
module: { rules: [ { test: /\.(tsx|ts)$/, loader: 'ts-loader' } ] }
修改后代碼
module: {
rules: [
{
test: /\.(tsx|ts)$/,
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, '../typescript.json')
}
}
] }
