【发布时间】:2018-05-08 13:30:32
【问题描述】:
我使用 create-react-app 并且我想使用来自 ./src 的绝对导入。
作为 Dan Abramov recommended 我添加了 .env 和 NODE_PATH=src 并且它有效。
但我的 eslint 不明白该模块已经存在。我收到错误 import/no-unresolved 和 import/extensions
这是我的 eslint 配置:
module.exports = {
parser: 'babel-eslint',
extends: 'airbnb',
rules: {
'react/no-did-mount-set-state': 'off',
'import/no-extraneous-dependencies': 'off',
'no-use-before-define': 'off',
'arrow-body-style': 'off',
// uncommit on developing
'no-console': 'off',
'no-debugger': 'off',
},
globals: {
browser: true,
fetch: true,
serviceworker: true,
describe: true,
it: true,
expect: true,
document: true,
},
};
当然,如果 vscode 可以通过 'src' 为我提供建议,那将是一件好事。
【问题讨论】:
-
你只是想隐藏 eslint 警告,还是想让它检测路径是否正确?
-
当然我可以把这些规则关掉,但可能有机会继续找文件。
-
在你不想被eslint-ed的文件开头使用
/* eslint-disable rulename */。 -
你的问题正是我的答案。非常感谢。
标签: javascript reactjs create-react-app