webpack打包项目时typescript报错The 'files' list in config file 'tsconfig.json' is empty.的解决方法

在用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')
     }
}
    ]  
}

猜你喜欢

转载自www.cnblogs.com/zhaozhipeng/p/10081215.html