VS代码不提供导入建议(Next JS,Javascript)



我花了最后一个小时试图让它发挥作用,但我找不到解决方案。我在上有一个组件/components/layout/layout.js.

我正在中使用此组件/pages/_app.js。然而,虽然esint看到我还没有导入它,但它没有提供自动导入它的建议(在快速修复菜单中(。我希望能够点击快速修复并查看建议的导入,就像我在Typescript项目中看到的那样(如果JS可以做到的话(

这是我的jsconfig.json:

{
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"jsx": "react",
"noImplicitAny": false,
"paths": {
"components/*": ["./components/*"]
}
},
"exclude": ["node_modules"]
}

这是我的eslintrc.js:

module.exports = {
env: {
commonjs: true,
node: true,
browser: true,
es6: true,
jest: true
},
extends: ['eslint:recommended', 'plugin:react/recommended'],
globals: {},
parser: 'babel-eslint',
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['react', 'import', 'react-hooks'],
ignorePatterns: ['node_modules/'],
rules: {
'react/react-in-jsx-scope': 0,
'react/prop-types': 0
},
settings: {
'import/resolver': {
alias: {
map: [['components', './components']]
}
},
react: {
version: 'latest' // "detect" automatically picks the version you have installed.
}
}
};

如果有人能为这里的配置提供一些建议,那就太好了。正如我所说,我在谷歌上搜索了很长时间,一直没能让它发挥作用。

非常感谢

更新tsconfig.json

添加任一

"checkJs": true

"allowJs": true

在tsconfig.json中的compilerOption下获取.中的suggetions

要启用VSCode自动导入,您需要在编译器选项中进行以下设置:

"checkJs": true

只需删除此项,即可在2023 中工作

"exclude": ["node_modules"]

最新更新