我将module-resolver
插件添加到.babelrc中,以便能够在我的nextjs项目中使用别名。
"plugins": [
[
"module-resolver",
{
"root": [
"./"
],
"alias": {
"components": "./app/components",
"pages": "./app/pages",
"themes": "./app/themes"
}
}
]
]
一切都运作良好,但自从我添加了此配置后,我的eslint配置会生成导入/未解决的错误。
[eslint]无法解析模块'components / HOC'的路径。 [导入/无未解决]
为了解决这个问题,我尝试更新我的.eslintrc.json设置:
"settings": {
"import/resolver": {
"components": "./app/components",
"pages": "./app/pages",
"themes": "./app/themes"
}
},
但是,这种新配置无效。我想正确地解决这个问题,你有没有想法正确解决这个问题?
谢谢!
在jsconfig.json
(tsconfig.json
for TypeScript)参考上添加此设置:https://github.com/tleunen/babel-plugin-module-resolver#editors-autocompletion
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"components": ["./app/components"],
"pages": ["./app/pages"],
"themes": ["./app/themes"]
}
}
}