我想使用Visual Studio代码在React Native中使用绝对路径。按照本教程:tuturial,我可以使它工作。
例如,在我的SRC文件夹中,我创建了package.json
:
{
"name": "@src"
}
但是当我尝试使用import A from '@src/...'
时,intellisense不起作用,通过在根中创建jsconfig.json
来修复它:
{
"compilerOptions": {
"module": "es6",
"paths": {
"@src/*": ["src/*"],
"@locale/*": ["locale/*"]
},
"baseUrl": "./"
}
}
它适用于from
部分,但不适用于import
部分,我要放/index
以使VS显示暗示,如果/index
不在那里,暗示没有显示。有没有什么方法可以让它工作,而不是在每次进口中加入/index
?
import { notShowHintHere } A from '@src/componentA'
import { showHintHere } A from '@src/componentA/index'
最后,我在这里找到了https://github.com/Microsoft/vscode/issues/24715的答案,更新了compilerOptions.module
的作品
"compilerOptions": {
"module": "commonjs"
}