---
type: snippet
tags: ['typescript', 'jsx', 'parser']
status: release
ctime: 2023-03-19
mtime: 2026-07-27
parent: '197'
---

```js
const { Parser } = require('acorn')
const JSXParser = Parser.extend(require('acorn-jsx')())

const isReactComponent = Boolean(
  JSON.stringify(
    JSXParser.parse(fileContent, {
      sourceType: 'module',
      ecmaVersion: 'latest',
    })
  ).includes('JSXIdentifier')
)
```

---

- https://github.com/vitejs/vite/discussions/3448
- https://github.com/jyash97/cra-to-vite/blob/master/src/index.js#L40-L43