We have a project built on angular-cli that also uses a package that was built on angular-cli. So our project has a tslint.json and so does the package. Since codelyzer is at the same version in both the project and the package then npm flattens the tree and installs codelyzer in the root node_modules folder; this is fine, and expected.
When we run ng lint we get this error:
Failed to load /Users/my-user/Documents/my-project/node_modules/my-package/tslint.json: Could not find custom rule directory: node_modules/codelyzer
This started happening since 3.x, and I cannot tell what the issue is, but I found a fix: just go into node_modules/my-package and run npm install codelyzer so it creates a local node_modules inside the package folder with just codelyzer in it at the same exact version as the codelyzer in the root node_modules. After doing this, ng lint works fine again.
I've searched for this issue on other packages and found a couple of similar reports:
The fix for ngx-uploader seems to be just removing tslint and codelyzer altogether but we cannot do this.
The issue reported on StackOverflow regarding the angular2-notifications package has no answers.
Perhaps another thing worth mentioning is that codelyzer and tslint are not listed in the package.json in our project because it is scaffolded with an in-house cli tool that basically just installs the packages without saving them to the package.json in a postinstall script.
This is all I could find so far. Any ideas why this is happening, and how we can fix it without having to go into the package folder and installing codelyzer manually everytime?
if you go with angular-cli 1.3 this should work. check if tslint.json is in the root package of your dependency, because this is the trigger to start linting on that dependency.
If it is there add this file to .npmignore, then publish a new version to your npm repository
Thanks for the comment!
you are welcome ;-) thanks for codelyzer
@lammers any way I can make this work on angular-cli 1.2 until 1.3 is stable? I tried adding it to .npmignore but now the project's tslint.json is analyzing the package and throwing errors.
I could work around this problem by creating a symlink in the nested node_modules directory to the project's node_modules/codelyzer directory:
node_modules/ng-socket-io/node_modules/codelyzer -> ../../codelyzer
I didn't generate project with angular-cli but after updating receive this error:
Error: Could not find custom rule directory: ./node_modules/codelyzer
I'm having this problem as well:
"angular/cli": "^1.4.5",
"codelyzer": "3.1.2",
yes we also facing this issue
"dependencies": {
"angular-redux/store": "^6.5.7",
"angular/common": "^4.0.0",
"angular/compiler": "^4.0.0",
"angular/core": "^4.0.0",
"angular/forms": "^4.0.0",
"angular/http": "^4.0.0",
"angular/platform-browser": "^4.0.0",
"angular/platform-browser-dynamic": "^4.0.0",
"angular/router": "^4.0.0",
"c3": "0.4.17",
"classlist.js": "^1.1.20150312",
"core-js": "^2.4.1",
"intl": "^1.2.5",
"lodash": "^4.17.4",
"ng2-page-scroll": "4.0.0-beta.11",
"ngx-popper": "^1.2.0",
"redux": "^3.7.2",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"angular/cli": "^1.2.6",
"angular/compiler-cli": "^4.0.0",
"types/c3": "0.4.44",
"types/jasmine": "2.5.38",
"types/node": "~6.0.60",
"codelyzer": "^3.2.1",
"jasmine-core": "^2.5.2",
"jasmine-spec-reporter": "^3.2.0",
"karma": "^1.4.1",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-intl-shim": "^1.0.3",
"karma-jasmine": "^1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.4",
"karma-teamcity-reporter": "^1.0.1",
"node-sass": "^4.5.3",
"phantomjs-polyfill": "^0.0.2",
"protractor": "~5.1.0",
"ts-node": "^2.0.0",
"tslint": "^4.5.0",
"typescript": "~2.4.0"
}
You need to exclude the npm_modules directory from linting (see https://stackoverflow.com/a/44777489/184245):
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**/*"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**/*"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**/*"
}]
I still have the same problem with either angular-cli 1.7.x or angular-cli 6.0.0 rc
How can I fix this?
@tilowestermann gave a good hint. If you lint node_modules folder tslint will take tslint.json from package's folder. For example @ngx-translate have one.
Making new angular apps with cli will make tslint.ts file inside src folder.
That means that the path "./node_modules" or just "node_modules/codelyzer" to the node modules will be wrong, make sure to target parent folder of src to get to modules folder.
"rulesDirectory": [
"../node_modules/codelyzer"
],
This works for me:
npm i codelyzer
```
"rulesDirectory": [
"node_modules/codelyzer"
],
```
running npm i codelyzer on the project resolved the issue.
Most helpful comment
Making new angular apps with cli will make tslint.ts file inside src folder.
That means that the path "./node_modules" or just "node_modules/codelyzer" to the node modules will be wrong, make sure to target parent folder of src to get to modules folder.
"rulesDirectory": [ "../node_modules/codelyzer" ],