all throughout my project, VSCode will automatically prompt to import a type (the yellow lightbulb appearing). Except within JEST test files (within my tests directory), I get no lightbulb. I can manually write the import, at which point any further imports within the same file are detected.
does anyone know how to fix this?
regards, Tilli
I was experiencing the same issue, Matt Bierner's response got me to the correct solution.
I had this project layout:
./lib/
./src/
./tests/
./tsconfig.json
In my tsconfig I had:
{
"compilerOptions": {
...
"outDir": "./lib",
"typeRoots": ["./node_modules/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
It was the tests being excluded, i.e. "**/*.spec.ts"
, which was preventing vscode from suggesting imports inside the tests.
Obviously, when this was removed, when build ran, the tests would end up in my ./lib
output dir.
I discovered a better solution to remedy both problems.
I split the tsconfig.json
as follows:
./lib/
./src/
./src/tsconfig.json
./tests/
./tsconfig.base.json
./tsconfig.json
./package.json
The ./tsconfig.base.json
file:
{
"compilerOptions": {
...
"outDir": "./lib",
"typeRoots": ["./node_modules/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
The ./tsconfig.json
file:
{
"extends": "./tsconfig.base.json"
}
The ./src/tsconfig.json
file:
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"outDir": "../lib"
},
"exclude": ["node_modules", "lib", "**/*.spec.ts"]
}
The build script was modified so that it would use the ./src/tsconfig.json
file, which required the -p ./src/
part to be added, as per the example below.
The ./package.json
file:
{
...
"scripts": {
...
"build": "tsc -p ./src/"
...
}
...
}
I hope this helps anyone that has the same issue.
For my case adding the following to tsconfig.json
fixed the problem.
{
...
"include": [
"src/**/*"
]
}
What is strange is that I didn't have this in my configuration from the beginning of the project, suddenly the import intellisense stopped from working, and had to add the above option to config file. I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With