TSLint: imports of lazy loaded libraries are forbidden (nx-enforce-module-boudries)
I have an app called home that has a lazy-loaded module, lazy. lazy imports a lib, shared, to use ui components from. Everything works but I get this error in Webstorm on my import statement within lazy.module.ts (e.g. import { SharedModule } from '@workspace/shared).
Is this expected? If I have a ui lib I would expect to be able to share that code with lazy-loaded modules. Also, shared lib is NOT a lazy-loaded lib anywhere in my routing configurations so I don't quite understand what is going on.
If I change the import statement to import { Shared Module } from '../../../../../libs/shared/src', the error goes away. I am confused.
I looked at the source code for this rule and it's as follows:
// if we import a library using loadChildre, we should not import it using es6 imports
if (this.onlyLoadChildren(sourceProject.name, targetProject.name, [])) {
this.addFailureAt(
node.getStart(),
node.getWidth(),
'imports of lazy-loaded libraries are forbidden'
);
return;
}
If you have done everything as you describe, then you shouldn't have problem. Could you please write the content of tsconfig.app.json file of the home app?
@stefanoslig - see below. I read the documentation and tried a few things which is why its commented out. I uncommitted it but my IDE is still giving me an error.
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc/apps/home",
"module": "es2015",
"types": []
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
],
"include": [
"**/*.ts",
// "../../../libs/shared/src/lib/index.ts"
]
}
To be clear, my code works fine regardless of the lint error. I am just wondering why I am getting it in the first place.
Yes, as I expected you have included shared module which is not a lazy module into the tsconfig.app.json. The lazy module as you said is the "lazy" module. So your tsconfig.app.json should be something like this .... .... "include": [ "**/*.ts", "../../../libs/lazy/src/lib/index.ts" ]
@stefanoslig lazy module is NOT in libs. It's in the home app folder (e.g. apps/home/src/app/lazy/lazy.module.ts)
The guide appears to only covers lazy loading a module defined in a library. I have the use case of lazy loading a module defined in the app. This lazy loaded app module exclusively uses a library so I expect that library will be bundled and loaded with that lazy loaded app module. Does this use case need to be similarly instrumented in tsconfig.app.json and tslint.json?
@fricker this is exactly what I am wondering as well. There is no documentation for this use case and I'd like to know if my IDE lint error is a false positive or if this use case isn't acceptable in Nx (which would seem odd to me).
This is already fixed in the master branch, please try with the latest version of Nx. If the problem persists, please open a new issue.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.