question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng generate with lint fix results in "no such file or directory" error

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [X] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Versions

NodeJS: v8.10.0 npm: 6.4.1

Angular CLI: 6.2.4
Node: 8.10.0
OS: win32 x64
Angular: 6.1.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.4
@angular-devkit/build-angular     0.8.4
@angular-devkit/build-optimizer   0.8.4
@angular-devkit/build-webpack     0.8.4
@angular-devkit/core              0.8.4
@angular-devkit/schematics        0.8.4
@angular/cli                      6.2.4
@ngtools/webpack                  6.2.4
@schematics/angular               0.8.4
@schematics/update                0.8.4
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.20.2

Repro steps

  1. Create a new project using ng new
  2. Edit the angular.json-File and add a Schematics-Configuration with the lintFix-Option:
	"schematics": {
		"@schematics/angular:component": {
			"lintFix": true
		}
	},

This Code can be inserted right before the projects-Node.

  1. Add a fixable tslint-rule, which collides with the default schematics. Examples are:
	"linebreak-style": [
		true,
		"CRLF"
	],
	"quotemark": [
		true,
		"double"
	],
  1. Create a component using ng generate component

The log given by the failure

>ng g component test
CREATE src/app/test/test.component.html (23 bytes)
CREATE src/app/test/test.component.spec.ts (614 bytes)
CREATE src/app/test/test.component.ts (261 bytes)
CREATE src/app/test/test.component.css (0 bytes)
UPDATE src/app/app.module.ts (388 bytes)
ENOENT: no such file or directory, scandir 'C:\Users\User\Angular\project\src\app\src\app\test'

Note, that it looks for project\src\app\src\app\test instead of project\src\app\test

Desired functionality

I would expect, that the lintFix-Option fixes all lint errors in the newly generated component.ts and component.spec.ts files. However, those files still use “LF” instead of “CRLF” and they still have Single-quotes instead of Double-Quotes.

Mention any other details that might be useful

The lintFix-Option disappeared in angular/cli@6.0 as mentioned in #11034 and came back with #11648. It should be part of angular/cli@6.2.x and it is part of it’s schematics schema file

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:14

github_iconTop GitHub Comments

3reactions
probert94commented, Nov 15, 2018

After noticing, that the lint-fixing seems to work for a colleague of mine, in the exact same project, we investigated a bit more. Here is what we found out:

  • Executing ng g service core/x --project app1 at the project root works and fixes all lint-errors.
  • Executing ng g service x inside apps/app1/src/app/core gives the mentioned error.

So it seems like the lint-fix only works, if the commands are executed at root-level. Hope this helps.

1reaction
asherbigcommented, Jan 29, 2020

Also having this problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't run ng lint on my angular-cli project - Stack Overflow
To fix the linting problem, add following into the .angular-cli.json ... Please run following commands to make sure, that both have the same ......
Read more >
ng test - Angular
Option Description Value Type Defau... ‑‑browsers Override which browsers tests are run against. string ‑‑code‑coverage Output a code coverage report. boolean false ‑‑code‑coverage‑exclude Globs to exclude...
Read more >
TSLint command-line interface - Palantir Open Source
--fix: Fixes linting errors for select rules. This may overwrite linted files. --force: Return status code 0 even if there are any lint...
Read more >
lint-staged - npm
prettierignore file. Running npx prettier . will ignore the entire vendor directory, throwing no errors. When lint-staged is added to the ...
Read more >
Identify and Fix Build and Deployment Errors in Your Angular ...
Usually, this can easily be fixed by stopping the ng serve process and re-running it because this allows the Webpack development server running ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found