Running lint fails after installing angular2-notifications
Asked Answered
U

3

10

I have created a new Angular4 project using Angular-CLI recently.

The problem I am having is after installing angular2-notifications , I get an error when running the ng lint command.

Error :

Failed to load C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\angular2-notifications\tslint.json: Could not find custom rule directory: C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\angular2-notifications\node_modules\codelyzer

Stacktrace :

at new FatalError (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\tslint\lib\error.js:40:23)
at Object.findConfiguration (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\tslint\lib\configuration.js:47:15)
at files.forEach (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\@angular\cli\tasks\lint.js:36:50)
at Array.forEach (native)
at lintConfigs.map (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\@angular\cli\tasks\lint.js:30:19)
at Array.map (native)
at Class.run (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\@angular\cli\tasks\lint.js:21:14)
at Class.run (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\@angular\cli\commands\lint.js:45:25)
at Class.Command.validateAndRun (C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\@angular\cli\ember-cli\lib\models\command.js:128:15)
at C:\Users\Gabriel\Documents\GitHub\Go-NoGo\GoNoGo\node_modules\@angular\cli\ember-cli\lib\cli\cli.js:92:22

I have turned to Google for this issue, without any luck. I have been to the GitHub repo and had no luck there either.

Then I went in the actual tslint.json file of angular2-notifications package.

I see this at the top :

"rulesDirectory": [
    "node_modules/codelyzer"
],

When I remove those 3 lines, the ng lint command works.

My question is, am I missing something here? I need this command to work and I don't think that modifying the package is an acceptable solution. Is this a bug in the package itself which I should report to them?

Thank you

Udela answered 1/6, 2017 at 0:48 Comment(0)
S
10

Exclude node_modules from your lint config in angular-cli.json:

"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/**/*"
    }]

The angular2-notifications project obviously shouldn't break ng lint for users. Still, I suppose it is also somewhat fair to say that a project shouldn't be trying to lint code that shouldn't be edited.

Struck answered 27/6, 2017 at 10:4 Comment(2)
angular-cli.json file has been renamed/replaced with angular.json in version 6 of Angular. The format of the file changed as well. See https://mcmap.net/q/377887/-where-is-the-file-angular-cli-json-in-the-new-angular-cli-versionAbbotsen
in my case we are using customized angular frame work and angular.json file is not there(neither angular-li.json) where to add those configurations thenInterviewee
M
0

The reason why I got the message was the absence of node_modules directory. After I ran npm install, the problem disappeared.

Microphyte answered 26/8, 2018 at 10:9 Comment(0)
A
0

I had the same issue, I found the solution by providing correct path for the node_modules.

I mean mine project is an ASP.net with Angular - Where directory structure is customized and "package.json" kept outside the angular app, Hence node_modules was also residing to the same directory where "package.json" is present.

So I was able to fix this issue by changing the "node_modules" path in tslint.ts as

"rulesDirectory": [
    "./../node_modules/codelyzer"
],
Argentiferous answered 5/4, 2021 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.