[英]Typescript baseUrl not working in React Typescript project
I defined the baseUrl
in my tsconfig.json
file:我在
tsconfig.json
文件中定义了baseUrl
:
"baseUrl": "src",
In .eslintrc.js
I have:在
.eslintrc.js
我有:
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
project: './tsconfig.json',
},
Now in eg index.tsx
I can import my components like import Layout from 'components/layout';
现在在例如
index.tsx
中,我可以导入我的组件,例如import Layout from 'components/layout';
When I run gatsby develop
I get some errors like:当我运行
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
What's missing here, why it isn't finding my components?这里缺少什么,为什么找不到我的组件?
You have to add import/resolver
settings in your .eslintrc.js
so Webpack can identify imports
of your components (I'm supposing that they have .tsx
extension)您必须在
.eslintrc.js
中添加import/resolver
设置,以便 Webpack 可以识别组件的imports
(我假设它们具有.tsx
扩展名)
settings: {
'import/resolver': {
node: {
paths: [
'src'
],
extensions: [
'.ts',
'.tsx'
]
}
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.