create-react-app打字稿“分析错误:意外的令牌”仅在启动和构建时

时间:2019-05-08 08:26:15

标签: javascript typescript eslint eslintrc

我有以下代码:

const RouterContext = createContext<IRouterContext>(null!)

VSCode不会出错,./node_modules/.bin/tsc --noEmit也不会出错。然后,当我启动我的应用程序或尝试构建它时,出现错误消息:

Failed to compile.

./src/router/Router.tsx
  Line 15:  Parsing error: Unexpected token, expected ","

> 15 | const RouterContext = createContext<IRouterContext>(null!)

我正在使用a forked version of create-react-app,尽管变化不大。所以我想这与eslint有关,即使eslint-loader仅再次匹配test: /\.(js|mjs|jsx)$/,。无论如何,我的配置如下:

module.exports = {
    parser: '@typescript-eslint/parser',
    extends: [
        'plugin:@typescript-eslint/recommended', // uses typescript-specific linting rules
        'plugin:react/recommended', // uses react-specific linting rules
        'plugin:prettier/recommended', // enables eslint-plugin-prettier and eslint-config-prettier
        'prettier/react', // disables react-specific linting rules that conflict with prettier
    ],
    parserOptions: {
        ecmaVersion: 2018,
        sourceType: 'module',
        ecmaFeatures: {
            jsx: true,
        },
        project: './tsconfig.json',
        tsconfigRootDir: './',
    },
    settings: {
        react: {
            version: 'detect',
        },
    },
    rules: {
        '@typescript-eslint/interface-name-prefix': 'always',
        '@typescript-eslint/no-explicit-any': 'always',
        '@typescript-eslint/explicit-function-return-type': 'off',
        '@typescript-eslint/no-non-null-assertion': 'off',
        '@typescript-eslint/no-use-before-define': 'off',
        '@typescript-eslint/indent': 'off',
        '@typescript-eslint/member-delimiter-style': {
            delimiter: 'none',
            requireLast: true,
        },
    },
}

我想念什么?

0 个答案:

没有答案