React Linting,缺少 "react" (import/extensions) 的文件扩展名
React Linting, Missing file extension for "react" (import/extensions)
我正在为我的 React 应用程序使用 Airbnb lint 设置
和行
import React from 'react';
给出错误
缺少 "react" 的文件扩展名 (import/extensions)
知道如何解决这个问题吗?
{
"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"
}
}
在 .eslintrc
的 rules
对象中,将 "import/extensions"
设置为 never
或 0
以避免这种情况。
您应该检查是否安装了 eslint-plugin-import
,Airbnb 样式指南配置使用它来处理导入和导出的 linting。如果你没有它,它会导致错误 Unable to resolve path to module '_module-name_'
and/or Missing file extension for "_module-name_" (import/extensions)
.
此外,由于您已将其安装在开发依赖项中,因此您可以 运行 类似 ./node_modules/.bin/eslint .
的东西或将 eslint 全局设置为 运行 eslint .
我正在为我的 React 应用程序使用 Airbnb lint 设置
和行
import React from 'react';
给出错误
缺少 "react" 的文件扩展名 (import/extensions)
知道如何解决这个问题吗?
{
"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"
}
}
在 .eslintrc
的 rules
对象中,将 "import/extensions"
设置为 never
或 0
以避免这种情况。
您应该检查是否安装了 eslint-plugin-import
,Airbnb 样式指南配置使用它来处理导入和导出的 linting。如果你没有它,它会导致错误 Unable to resolve path to module '_module-name_'
and/or Missing file extension for "_module-name_" (import/extensions)
.
此外,由于您已将其安装在开发依赖项中,因此您可以 运行 类似 ./node_modules/.bin/eslint .
的东西或将 eslint 全局设置为 运行 eslint .