1. 程式人生 > >webpack打包專案時typescript報錯The 'files' list in config file 'tsconfig.json' is empty.的解決方法

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