I'm using parcel, typescript, react and a custom .babelrc.
When starting parcel or building with parcel, the error below occurs. It can't handle the generic.
Full demo project here:
https://github.com/Kombustor/demo-parcel-error
Just npm install and npm run dev
Parcel should bundle and start without an error.
The following error occurs:
脳 SyntaxError: [path]\src\app\app.tsx: Unexpected token, expected "{" (4:48)
3 |
> 4 | export default class App extends React.Component<AppProps> {
| ^
at Object.raise ([path]\node_modules\@babel\parser\lib\index.js:3831:17)
at Object.unexpected ([path]\node_modules\@babel\parser\lib\index.js:5143:16)
at Object.expect ([path]\node_modules\@babel\parser\lib\index.js:5135:28)
at Object.parseClassBody ([path]\node_modules\@babel\parser\lib\index.js:7998:10)
at Object.parseClass ([path]\node_modules\@babel\parser\lib\index.js:7973:10)
at Object.parseExportDefaultExpression ([path]\node_modules\@babel\parser\lib\index.js:8394:19)
at Object.parseExport ([path]\node_modules\@babel\parser\lib\index.js:8299:31)
at Object.parseStatementContent ([path]\node_modules\@babel\parser\lib\index.js:7347:27)
at Object.parseStatement ([path]\node_modules\@babel\parser\lib\index.js:7243:17)
at Object.parseBlockOrModuleBlockBody ([path]\node_modules\@babel\parser\lib\index.js:7810:25)
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0
| Node |v10.13.0
| npm/Yarn |6.4.1
| Operating System |Windows 10 Pro
By adding "@babel/typescript" to the preset section in .babelrc it worked.
I had the same issue and it happened because I had named the Babel file .babelrc.json. Naming it .babelrc fixed it.
Most helpful comment
By adding "@babel/typescript" to the preset section in .babelrc it worked.