I have a workspace named nhaancs. Inside my workspace has:
web-portal models, which have a model named UserModel, exported in the index.ts file.Inside apps/web-portal/src/app:
UserModel in AppComponent by the following: import {UserModel} from '@nhaancs/models' => It's OKUserService (use providedIn: 'root', not provided in providers array) and import UserModel like above => The code compiled success, app still working but VSCode display error Cannot find module '@nhaancs/models' or its corresponding type declarations.UserSevice in providers array of AppModule, the error is gone.
VSCode do not display the error even the service is not imported into app module's providers.
npx create-nx-workspace@latestnhaancsweb-portalmodelsmodels create an empty class named UserModel and export it in index.tsapps/src/app/app.component.ts, import UserModel: import {UserModel} from '@nhaancs/models' => It's OK.apps/src/app, run command ng g s user --skipTests to create user.service.ts fileapps/src/app/user.service.ts, import UserModel: import {UserModel} from '@nhaancs/models' => VSCode display error Cannot find module '@nhaancs/models' or its corresponding type declarations. (Even The code compiled success, app still working)apps/src/app/app.module.ts, import UserService to providers array => the error in apps/src/app/user.service.ts file is gone@NgModule({
...
providers: [UserService], // <<< here
...
})
export class AppModule {}
@nrwl/angular : 10.0.6
@nrwl/cli : 10.0.6
@nrwl/cypress : 10.0.6
@nrwl/eslint-plugin-nx : Not Found
@nrwl/express : Not Found
@nrwl/jest : 10.0.6
@nrwl/linter : Not Found
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 10.0.6
@nrwl/web : Not Found
@nrwl/workspace : 10.0.6
typescript : 3.9.7
@nhaancs have you checked if your tsconfig > path contains the name you're expecting?
Also, I have been experiencing a lot of inconsistencies due to TSLint extension for VSCode. Sometimes I need to restart VSCode to get the correct intellisense
@nhaancs have you checked if your tsconfig > path contains the name you're expecting?
Also, I have been experiencing a lot of inconsistencies due to TSLint extension for VSCode. Sometimes I need to restart VSCode to get the correct intellisense
Yes, the paths is correct
This may be related to #3409
This may be related to #3409
I think the situation is quite different. The errors only happen in the file that not a component.
I was seeing this because the version of VS Code on my work machine was using an outdated version of TypeScript by default. Telling VS Code to use the workspace version of TS (3.9) fixed the issue for me. I found this solution from the Angular CLI issues.
this is a duplicate of #8138 and was addressed in version 10 via #17586.
The fix requires TypeScript 3.9 which leverages the usage of the new "solutions style" tsconfig files. You can read about this here https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-rc/#solution-style-tsconfig
_Originally posted by @alan-agius4 in https://github.com/angular/angular-cli/issues/17873#issuecomment-640572787_
Ah, let me explain what is happening here.
The editor will traverse upwards from the file that you have open to find a file named tsconfig.json (it must be exactly this). In Nx 10 (and Angular CLI 10), that file is a solution tsconfig.json which means it references other tsconfig files such as the tsconfig.app.json. The tsconfig.app.json only includes the main.ts and the polyfills.ts to limit what get's typechecked during the build. This issue is actually specific to Angular apps in Nx because in our React and Node apps, our tsconfig.app.json includes all .ts files. An ugly solution to this issue is maybe to include all .ts files in Angular apps as well but I'll think on it for a bit.
I get this error just implementing the Nx example for shared code: https://nx.dev/angular/tutorial/07-share-code
A solution for this is restore the tsconfig.json of the project (angular app) to the latest version before the update. It seems like the "circular" reference is causing the problem here.
The tsconfig.json now looks like this.
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
}
}
A solution for this is restore the
tsconfig.jsonof the project (angular app) to the latest version before the update. It seems like the "circular" reference is causing the problem here.The
tsconfig.jsonnow looks like this.{ "extends": "../../../tsconfig.base.json", "compilerOptions": { "types": ["node", "jest"] } }
@nestorvanz Unfortunately, this solution is not working for me
Ah, let me explain what is happening here.
The editor will traverse upwards from the file that you have open to find a file named
tsconfig.json(it must be exactly this). In Nx 10 (and Angular CLI 10), that file is a solution tsconfig.json which means it references other tsconfig files such as thetsconfig.app.json. Thetsconfig.app.jsononly includes themain.tsand thepolyfills.tsto limit what get's typechecked during the build. This issue is actually specific to Angular apps in Nx because in our React and Node apps, ourtsconfig.app.jsonincludes all.tsfiles. An ugly solution to this issue is maybe to include all.tsfiles in Angular apps as well but I'll think on it for a bit.
@FrozenPandaz do we have any better solutions for this issue
A solution for this is restore the tsconfig.json of the project (angular app) to the latest version before the update.
That is a solution. However, I would not recommend it because it re-introduces with having a single tsconfig for both runtime and tests.
It seems like the "circular" reference is causing the problem here.
Can you elaborate on the "circular" reference?
@FrozenPandaz do we have any better solutions for this issue
A preferable solution would possibly look something like:
apps/app1/tsconfig.all.json or apps/app1/tsconfig.base.json (name pending)"include": ["**/*.ts"]apps/app1/tsconfig.jsontsconfig.*.json will still use those files. Files
Most helpful comment
That is a solution. However, I would not recommend it because it re-introduces with having a single tsconfig for both runtime and tests.
Can you elaborate on the "circular" reference?
A preferable solution would possibly look something like:
apps/app1/tsconfig.all.jsonorapps/app1/tsconfig.base.json(name pending)"include": ["**/*.ts"]apps/app1/tsconfig.jsontsconfig.*.jsonwill still use those files. Files