React Linting,缺少"react"的文件扩展名(导入/扩展名)



我正在使用Airbnb lint设置我的React App

和线

import React from 'react';

给出错误

缺少" react"(导入/扩展)的文件扩展名

任何想法如何解决?

{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.17.1",
    "firebase": "^4.6.2",
    "jquery": "^3.2.1",
    "react": "^16.1.1",
    "react-dom": "^16.1.1",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "^1.0.17"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "sass": "sass --watch src/styles/scss:src/styles/css",
    "sass:build": "sass src/styles/scss:src/styles/css"
  },
  "devDependencies": {
    "eslint": "^4.12.0",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^6.0.2",
    "eslint-plugin-react": "^7.5.1"
  }
}

在您的rules对象中,.eslintrc"import/extensions"设置为never0

您应该检查是否已安装eslint-plugin-import,Airbnb样式指南配置使用它来处理进口和导出的覆盖。如果没有它,它会导致错误Unable to resolve path to module '_module-name_'和/或Missing file extension for "_module-name_" (import/extensions)

同样,由于您将其安装在DEV依赖性中,因此您可以在全球范围内运行诸如./node_modules/.bin/eslint .或设置ESLINT之类的东西以运行eslint .

相关内容

最新更新