【发布时间】:2021-04-09 10:02:33
【问题描述】:
我尝试在我的 Gatsby 和 Typescript 项目中创建导入别名。我使用 npm 包eslint-import-resolver-alias。
所以我可以使用:
import Layout from '@components/Layout';
在gatsby-node.js 我有:
const path = require('path');
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
@components: path.resolve(__dirname, 'src/components'),
@static: path.resolve(__dirname, 'static'),
},
},
});
};
在.eslintrc.js 我有:
alias: [['@components', './src/components']]
我有:
"baseUrl": "./src",
"paths": {
"@components": ["/components"]
现在我在 VSCode 中收到此错误:
无法解析模块路径 'components/layout'.eslintimport/no-unresolved
【问题讨论】:
标签: typescript gatsby eslint-config-airbnb typescript-eslintparser