Reputation: 4292
ERROR in ./productFlow/index.tsx 3:12 Module parse failed: Unexpected token (3:12) File was processed with these loaders: * ./node_modules/awesome-typescript-loader/dist/entry.js You may need an additional loader to handle the result of these loaders. | import React from 'react'; | export default props => { return ( |
<p>Compiled Successfully</p>
| );
It appears to fail when it hits JSX code (in a .tsx file). Is at-loader not capable of handling this? I searched around for a react loader but the examples I saw were closer to my own:
const webpack = require("webpack");
const dotEnvWebpack = require("dotenv-webpack");
const path = require("path");
const webpackConfiguration = {
entry : {
productFlow : path.join(__dirname, "productFlow/index.tsx")
, registrationFlow : path.join(__dirname, 'registrationFlow/index.tsx')
}
, output : {
filename : "outputFiles/[name].output.js"
, path : path.resolve(__dirname, "")
, publicPath : '/'
}
, watch : true
, watchOptions : { aggregateTimeout : 300 }
, devtool : 'inline-source-map'
, mode : "development"
, devServer : {
port: 3000
, contentBase : path.join(__dirname, "devIndex.html")
, hot : true
, historyApiFallback : true
}
, plugins : [
new webpack.HotModuleReplacementPlugin(),
new dotEnvWebpack
]
, node : {
fs: "empty" // for dotenv to work correctly
}
, resolve : { extensions : ['.ts', '.tsx', '.js'] }
, module : {
rules : [{
test : /\.tsx?$/
, use : 'awesome-typescript-loader'
, exclude : [/node_modules/, /outputFiles/]
}]
}
, externals : {
'react' : 'React'
, 'react-dom' : 'ReactDOM'
}
};
module.exports = webpackConfiguration;
Upvotes: 5
Views: 14727
Reputation: 4292
This was not a webpack issue, it was tsconfig relaxed. The loader recognized JSX after adding this line to tsconfig.json:
"jsx": "react",
Upvotes: 7