如何向eslintrc添加绝对路径?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何向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';
正在编译并且可以工作,但是坚持说他没有找到模块。
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"]
以上是关于如何向eslintrc添加绝对路径?的主要内容,如果未能解决你的问题,请参考以下文章