You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native项目中react-native-reanimated引发ESLint解析错误求助

React Native中react-native-reanimated引发ESLint解析错误

在React Native项目中引入react-native-reanimated后,动画运行正常,但通过CLI或GitHub Workflow执行ESLint时出现解析错误,提示找不到模块/myAppPath/node_modules/react-native-reanimated/lib/module/index,要求验证package.json的main入口是否有效。即使只添加一行该库的导入语句也会触发类似错误,注释所有相关导入后错误消失。

已尝试过以下操作,但均无法解决问题:

  • 重新安装react-native-reanimated包
  • 删除并重装node_modules
  • 删除yarn.lock后重新执行yarn

相关配置文件

eslintrc.json

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "useJSXTextNode": true,
    "project": "./tsconfig.json",
    "ecmaVersion": 2023
  },
  "extends": [
    "@react-native-community",
    "plugin:react/recommended",
    "plugin:react-native/all",
    "plugin:import/recommended",
    "eslint:recommended",
    "airbnb",
    "airbnb/hooks",
    "prettier"
  ],
  "plugins": [
    "react",
    "react-native",
    "import",
    "prettier",
    "@typescript-eslint"
  ],
  "root": true,
  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "jsx": "never",
        "ts": "never",
        "tsx": "never"
      }
    ],
    "@typescript-eslint/no-unused-vars": [
      "error",
      {
        "argsIgnorePattern": "^_"
      }
    ],
    "react/no-array-index-key": "off",
    "consistent-return": "off",
    "import/no-extraneous-dependencies": "off",
    "import/order": [
      "error",
      {
        "alphabetize": {
          "caseInsensitive": true,
          "order": "asc"
        },
        "groups": [
          "builtin",
          "external",
          "internal",
          "sibling",
          "parent",
          "index"
        ],
        "pathGroups": [
          {
            "group": "builtin",
            "pattern": "react-native",
            "position": "before"
          },
          {
            "group": "builtin",
            "pattern": "react",
            "position": "before"
          }
        ],
        "pathGroupsExcludedImportTypes": [
          "react",
          "react-native"
        ]
      }
    ],
    "import/prefer-default-export": "off",
    "no-console": "off",
    "no-nested-ternary": "off",
    "no-plusplus": "off",
    "no-shadow": "off",
    "no-use-before-define": [
      "error",
      {
        "classes": true,
        "functions": true,
        "variables": false
      }
    ],
    "react-hooks/exhaustive-deps": "off",
    "react-native/no-color-literals": "off",
    "react-native/no-inline-styles": "warn",
    "react-native/no-raw-text": "off",
    "react-native/split-platform-components": "off",
    "react/function-component-definition": [
      "error",
      {
        "namedComponents": [
          "arrow-function",
          "function-declaration"
        ]
      }
    ],
    "react/jsx-filename-extension": [
      "warn",
      {
        "extensions": [
          ".jsx",
          ".tsx"
        ]
      }
    ],
    "react/jsx-no-constructed-context-values": "off",
    "react/jsx-props-no-spreading": "off",
    "react/prop-types": "off",
    "react/react-in-jsx-scope": "off",
    "react/require-default-props": "off",
    "react/no-unused-prop-types": "off"
  },
  "overrides": [
    {
      "files": [
        "./src/store/**"
      ],
      "rules": {
        "no-param-reassign": "off",
        "camelcase": "off"
      }
    }
  ],
  "settings": {
    "import/resolver": {
      "alias": {
        "extensions": [
          ".ts",
          ".tsx"
        ],
        "map": [
          [
            "@src",
            "./src"
          ],
          [
            "@components",
            "./src/components"
          ],
          [
            "@screens",
            "./src/screens"
          ],
          [
            "@assets",
            "./assets"
          ]
        ]
      }
    }
  }
}

tsconfig.json

{
  "include": [
    "custom.d.ts",
    "src/**/*",
    "index.ts",
    "nativewind-env.d.ts",
    "assets/**/*.ts",
    "react-native.config.js"
  ],
  "exclude": [
    "__tests__/" // exclude test files
  ],
  "compilerOptions": {
    /* Visit https://aka.ms/tsconfig to read more about this file */
    "baseUrl": "./",
    "paths": {
      "@components/*": [
        "./src/components/*"
      ],
      "@screens/*": [
        "./src/screens/*"
      ],
      "@src/*": [
        "./src/*"
      ],
      "@assets/*": [
        "./assets/*"
      ],
    },
    /* Basic Options */
    "target": "ES6",
    "jsx": "react-jsx",
    "module": "commonjs",
    "allowJs": true,
    "resolveJsonModule": true,
    "noEmit": true,
    "skipLibCheck": true,
    /* Strict Type-Checking Options */
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    /* Additional Checks */
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": false,
    "noFallthroughCasesInSwitch": true,
    /* Module Resolution Options */
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
}

内容的提问来源于stack exchange,提问作者Asad Shabir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:05:06