我使用的是从next导入模块。尝试导入这样的组件。import Navbar from '@/components/Navbar/Navbar';
当我运行npm运行lint。我得到以下错误。1:20 Error: Unable to resolve path to module '@/components/Navbar/Navbar'. import/no-unresolved
这是我的jsconfig.json
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@/components/*": ["components/*"],
"@/pages/*": ["pages/*"],
"@/styles/*": ["styles/*"]
}
}
}
这是eslintrc.json
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 11,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"alias": {
"map": [
["@components", "./components/*"],
["@images", "./public/*"],
["@/pages/*", "pages/*"],
["@/styles/*", "styles/*"]
],
"extensions": [".js", ".jsx"]
}
}
},
"plugins": ["react", "react-hooks", "jest"],
"rules": {
"react/jsx-props-no-spreading": 0,
"react/react-in-jsx-scope": "off",
"import/extensions": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/display-name": 1,
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error",
"import/no-unresolved": [2, { "caseSensitive": false }]
}
}
1条答案
按热度按时间xlpyo6sf1#
在您的
eslintrc.json
中,您有你应该有:
换句话说,在
@
和components
之间应该有一个/
,因为jsconfig.json
中的路径别名是