reactjs - 如何将绝对路径添加到 eslintrc?
问题描述
在我的 React 应用程序中,我试图向 SRC 添加绝对路径,以防止所有 ../..
我有以下 tsconfig :
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"noImplicitAny": false,
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"baseUrl": "src"
},
"include": [
"src"
]
}
在一个组件中,我执行以下操作:
import { RootState } from 'app/services/store/rootReducer';
import { UsersActions } from 'app/services/store';
是编译和工作,但 eslint 说他没有找到一个模块。
Cannot find module 'app/services/store/rootReducer'
我试图将其添加到 eslintrc.json
"plugins": [
"react"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"settings": {
"import/resolver": {
"node": {
"paths": ["src"]
},
"es6": {
"paths": ["src"]
}
}
}
}```
But nothing changes.
How can I make absolute path work correctly ?
解决方案
您应该像这样更改设置。之后,您必须安装“ eslint-plugin-import ”和“ eslint-import-resolver-babel-module ”
settings: {
"import/resolver": {
node: {},
"babel-module": {
root: ["./src"]
}
}
}
推荐阅读
- python - python2.7中处理UnicodeEncodeError
- time-series - 为什么简单的指数平滑会为不同的观察结果返回相同的预测
- java - 从自定义列表视图中获取每个选中的项目
- arrays - 创建具有多个元素的 Bash 数组
- mobile - 允许在框架中上下触摸控制
- linux - Linux + Wordpress:如何从 Linux Cron 作业中触发函数?
- c++ - 基于管道(非 FIFO)文件权限检查器 C++ 的服务器/客户端
- r - R - 如何创建任意列表列表
- javascript - 页面刷新时受控输入不清晰(Microsoft Edge)
- javascript - 如何对字典数组中的内容进行分组?