我的导入路径和点击打开文件有什么问题?
What's wrong with my importing path & clicking to open file?
我刚开始一份新工作,因此也是一个新的设置。并没有什么不同,但出于某种原因,我遇到了 2 个与导入路径显示相关的问题,单击 files/components 打开文件不起作用。
会不会是jsconfig
文件的原因?:
{
"compilerOptions": {
"checkJs": false,
"target": "es2017",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",
"paths": {
"test-utils": ["../jest.config.js"]
}
},
"exclude": ["node_modules", "build"]
}
问题 1
- 我的导入路径有时显示相对路径,有时不显示。示例
Provider
正确地从 node_modules
导入,但 Checkbox
没有:
import React from 'react';
import { Provider } from 'react-redux'; // YES
import { Checkbox } from '../../../node_modules/antd/lib/index'; // NO
export default function test() {
return (
<Provider>
<Checkbox />
</Provider>
);
}
所以在 VSCode 中,我检查了我的设置 JavaScript › 首选项:导入模块说明符。当前设置为 auto
。如果我将其更改为 relative
,则看不到任何更改。如果我将其更改为 non-relative
,复选框导入将更改为:
import { Checkbox } from '../node_modules/antd/lib/index';
但这仍然不是我对 node_module 导入的期望。
如果我删除 JSConfig,那么导入 { Checkbox } 行为看起来是正确的。然而,我显然是我团队中唯一遇到此问题的人。
问题 2
- 有时通过按
Command key (⌘) + Click
单击组件打开文件不会打开文件,有时会。
import StatusKey from '../../components/StatusKey'; // (⌘) + Click does not work
import { columns } from './tableColumns'; // (⌘) + Click works
动图:http://recordit.co/GKZfRa7emo
但是,如果我将 StatusKey 导入更改为 import StatusKey from 'components/StatusKey/index';
,那么它就可以工作了。
如果我删除了 JSConfig,则单击 Status 键将与原始导入一起使用。
感谢您的见解
jsconfig 需要 "module": "commonjs",
作为 compilerOptions
的一部分
我刚开始一份新工作,因此也是一个新的设置。并没有什么不同,但出于某种原因,我遇到了 2 个与导入路径显示相关的问题,单击 files/components 打开文件不起作用。
会不会是jsconfig
文件的原因?:
{
"compilerOptions": {
"checkJs": false,
"target": "es2017",
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",
"paths": {
"test-utils": ["../jest.config.js"]
}
},
"exclude": ["node_modules", "build"]
}
问题 1
- 我的导入路径有时显示相对路径,有时不显示。示例
Provider
正确地从node_modules
导入,但Checkbox
没有:
import React from 'react';
import { Provider } from 'react-redux'; // YES
import { Checkbox } from '../../../node_modules/antd/lib/index'; // NO
export default function test() {
return (
<Provider>
<Checkbox />
</Provider>
);
}
所以在 VSCode 中,我检查了我的设置 JavaScript › 首选项:导入模块说明符。当前设置为 auto
。如果我将其更改为 relative
,则看不到任何更改。如果我将其更改为 non-relative
,复选框导入将更改为:
import { Checkbox } from '../node_modules/antd/lib/index';
但这仍然不是我对 node_module 导入的期望。
如果我删除 JSConfig,那么导入 { Checkbox } 行为看起来是正确的。然而,我显然是我团队中唯一遇到此问题的人。
问题 2
- 有时通过按
Command key (⌘) + Click
单击组件打开文件不会打开文件,有时会。
import StatusKey from '../../components/StatusKey'; // (⌘) + Click does not work
import { columns } from './tableColumns'; // (⌘) + Click works
动图:http://recordit.co/GKZfRa7emo
但是,如果我将 StatusKey 导入更改为 import StatusKey from 'components/StatusKey/index';
,那么它就可以工作了。
如果我删除了 JSConfig,则单击 Status 键将与原始导入一起使用。
感谢您的见解
jsconfig 需要 "module": "commonjs",
作为 compilerOptions