Parcel: Parcel + Typescript + React + custom .babelrc: Unexpected token, expected "{"

Created on 23 Feb 2019  路  2Comments  路  Source: parcel-bundler/parcel

馃悰 bug report

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.

馃帥 Configuration / 馃捇 Code Sample

Full demo project here:
https://github.com/Kombustor/demo-parcel-error

Just npm install and npm run dev

馃 Expected Behavior

Parcel should bundle and start without an error.

馃槸 Current Behavior

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)

馃實 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11.0
| Node |v10.13.0
| npm/Yarn |6.4.1
| Operating System |Windows 10 Pro

Most helpful comment

By adding "@babel/typescript" to the preset section in .babelrc it worked.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings