[英]React typescript eslint error Parsing error: Unexpected token ! How to fix this?
所以这是我的 index.tsx:
import React from 'react';
import { createRoot } from 'react-dom/client';
import App from './App';
const container = document.getElementById('root')!;
const root = createRoot(container);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
这是我的 eslintrc.js:
module.exports = {
env: {
browser: true,
es2021: true
},
extends: ['plugin:react/recommended', 'prettier'],
overrides: [
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: ['./tsconfig.json']
}
}
],
parserOptions: {
parser: 'babel-eslint',
ecmaFeatures: {
jsx: true
},
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: ['react', '@typescript-eslint', 'prettier', 'simple-import-sort'],
我试过安装 babel-eslint,并像解析器一样添加它? 但它没有帮助
所以问题来了,如何解决“error Parsing error: Unexpected token?”的问题?
通过添加"parser": "@typescript-eslint/parser",
将typescript-eslint
设置为您的解析器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.