angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng g c cname --flat gives directory error

Open nbunney opened this issue 10 years ago • 7 comments

Please provide us with the following information:

  1. OS? MacOS Sierra

  2. Versions. angular-cli: 1.0.0-beta.14 node: 6.6.0 os: darwin x64

  3. Repro steps. App created with cli ng g c name_of_component cd to the component directory ng g c name_of_sub_component --flat -it -is

  4. The log given by the failure. installing component Error locating module for declaration Error: ENOENT: no such file or directory, scandir '/Users/nathan/Sites/A2Cl/first-app/src/app/Volumes/Macintosh HD/other' Directory is incorrect It adds /Volumes/Macintosh HD/ in the middle of a perfectly good path.

  5. Mention any other details that might be useful. I am comfortable in Angular new to Angular 2. Going through an online course and hit this error.


    Thanks! We'll be in touch soon.

nbunney avatar Sep 16 '16 23:09 nbunney

Just verified that on my system this is repeatable.

  • ng new first-app2
  • cd first-app2
  • ng g c other
  • cd src/app/other/
  • ng g c another --flat -it -is

installing component Error locating module for declaration Error: ENOENT: no such file or directory, scandir '/Users/nathan/Sites/A2Cl/first-app2/src/app/Volumes/Macintosh HD/other'

nbunney avatar Sep 16 '16 23:09 nbunney

I have verified that I can use ng g c from the root of the project but any other directory will give this error even without the --flat flag.

nbunney avatar Sep 20 '16 16:09 nbunney

I think this has since been fixed, this is the result I'm getting in the latest versions:

kamik@T460p MINGW64 /D/sandbox/master-proj (master)
$ ng g c other
installing component
  create src\app\other\other.component.css
  create src\app\other\other.component.html
  create src\app\other\other.component.spec.ts
  create src\app\other\other.component.ts

kamik@T460p MINGW64 /D/sandbox/master-proj (master)
$ cd src/app/other/

kamik@T460p MINGW64 /D/sandbox/master-proj/src/app/other (master)
$ ng g c another --flat -it -is
installing component
  create src\app\another.component.spec.ts
  create src\app\another.component.ts

filipesilva avatar Oct 03 '16 12:10 filipesilva

Yup, works for me now too.

nbunney avatar Oct 03 '16 14:10 nbunney

Still broken.

The location of your app.module.ts is fundamental to the success of 'ng g c my-component' command.

I'd moved mine into a subfolder 'src\app\shared', along with the other app.* files and this resulted in the error 'Error locating module for declaration'

Moving app.module.ts back to the 'src\app' folder fixed the issue and the command succeeded either from the '\src' folder or the '\src\app' folder.

I was also able to successfully issue the command from wherever app.module.ts lived, e.g. '\src\app\shared'

sophistyx avatar Nov 03 '16 14:11 sophistyx

@sophistyx what you seem to be describing isn't the original issue here. Please open a new issue.

filipesilva avatar Nov 04 '16 17:11 filipesilva

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.