简体   繁体   中英

Migrate from webpack v1 to v2 with webpack-cli produces error for tsx

I get this error when running build after migration, and not sure if it can't recognise tsx files or something inside of tsx file that it doesn't like:

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

Content of 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:}

My webpack config after migration script:

https://pastebin.com/KX02ZRUY

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

Doesn't recognize tsx.

I would change

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

To standard docs : https://webpack.js.org/guides/webpack-and-typescript/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM