I've spent the last hour trying to get this working and I can't find a solution. I have a ponent at ./ponents/layout/Layout.js.
I'm using this ponent in ./pages/_app.js. However, while eslint sees that I haven't imported it, it doesn't offer a suggestion to autoimport it (in the quick fix menu). I would like to be able to click quick fix and see the suggested import, as I get in Typescript projects (if this is even possible with JS.)
Here is my jsconfig.json:
{
"pilerOptions": {
"target": "es2020",
"module": "esnext",
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"jsx": "react",
"noImplicitAny": false,
"paths": {
"ponents/*": ["./ponents/*"]
}
},
"exclude": ["node_modules"]
}
and this is my eslintrc.js:
module.exports = {
env: {
monjs: true,
node: true,
browser: true,
es6: true,
jest: true
},
extends: ['eslint:remended', 'plugin:react/remended'],
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: [['ponents', './ponents']]
}
},
react: {
version: 'latest' // "detect" automatically picks the version you have installed.
}
}
};
It would be really great if someone could offer some suggestions for the configs here. As I've said, I've trawled through Google for a long time and haven't been able to get it working.
Many thanks
I've spent the last hour trying to get this working and I can't find a solution. I have a ponent at ./ponents/layout/Layout.js.
I'm using this ponent in ./pages/_app.js. However, while eslint sees that I haven't imported it, it doesn't offer a suggestion to autoimport it (in the quick fix menu). I would like to be able to click quick fix and see the suggested import, as I get in Typescript projects (if this is even possible with JS.)
Here is my jsconfig.json:
{
"pilerOptions": {
"target": "es2020",
"module": "esnext",
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"jsx": "react",
"noImplicitAny": false,
"paths": {
"ponents/*": ["./ponents/*"]
}
},
"exclude": ["node_modules"]
}
and this is my eslintrc.js:
module.exports = {
env: {
monjs: true,
node: true,
browser: true,
es6: true,
jest: true
},
extends: ['eslint:remended', 'plugin:react/remended'],
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: [['ponents', './ponents']]
}
},
react: {
version: 'latest' // "detect" automatically picks the version you have installed.
}
}
};
It would be really great if someone could offer some suggestions for the configs here. As I've said, I've trawled through Google for a long time and haven't been able to get it working.
Many thanks
include
or files
option in jsconfig.json
(2) add // @ts-check
at the beginning of both files.
– hackape
Commented
Apr 26, 2021 at 16:13
tsconfig.json
instead and turn on allowJs: true
to fool the editor to believe this is a TS project.
– hackape
Commented
Apr 26, 2021 at 16:16
add either
"checkJs": true
or
"allowJs": true
under pilerOption in tsconfig.json to get the suggetions in.
post update just reload the vs code
To enable VSCode auto imports you need the following setting inside piler options:
"checkJs": true
Just remove this, it work at 2023
"exclude": ["node_modules"]