2017-05-29 64 views
1

迁移后运行构建时出现此错误,并且不确定它是否无法识别tsx文件或其不喜欢的tsx文件:使用webpack-cli从webpack v1迁移到v2会产生tsx的错误

Failed to compile. Error in ./src/index_app.tsx Module parse failed: /src/index_app.tsx Unexpected token (17:26) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (17:26) @ multi main

内容index_app.tsx的:

17:const rootReducer = (state:any, action:any) => { 
18: if (action.type === Actions.RESET_GLOBAL_STATE) { 
19:  state = undefined; 
20: } 
21: return reducers(state, action) 
22:} 

迁移脚本后,我的WebPack配置:

https://pastebin.com/KX02ZRUY

回答

0

not sure if it can't recognise tsx files or something inside of tsx file that it doesn't like

不识别tsx。

我会改变

{ 
     test: /\.(ts|tsx)$/, 
     include: paths.appSrc, 
     use: [{ 
      loader: 'ts-loader' 
     }], 
    } 

要标准文档:https://webpack.js.org/guides/webpack-and-typescript/

{ 
    test: /\.tsx?$/, 
    exclude: /node_modules/, 
    use: [ 'ts-loader' ] 
}