[英]Typescript baseUrl not working in React Typescript project
我在tsconfig.json
文件中定義了baseUrl
:
"baseUrl": "src",
在.eslintrc.js
我有:
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json',
},
現在在例如index.tsx
中,我可以導入我的組件,例如import Layout from 'components/layout';
當我運行gatsby develop
時,會出現一些錯誤,例如:
If you're trying to use a package make sure that 'components/layout' is installed. If you're trying to use a local file make sure that the path is correct.
error undefined failed
這里缺少什么,為什么找不到我的組件?
您必須在.eslintrc.js
中添加import/resolver
設置,以便 Webpack 可以識別組件的imports
(我假設它們具有.tsx
擴展名)
settings: {
'import/resolver': {
node: {
paths: [
'src'
],
extensions: [
'.ts',
'.tsx'
]
}
}
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.