angular-cli: Cannot create components with CLI on Windows
We are not able to generate components on a project that’s using a slightly different directory structure. After a bit of testing, it seems like it’s a Windows path issue as generating components on Macbooks are working just fine.
Bug Report or Feature Request (mark with an x
)
- [ x ] bug report -> please search issues before submitting
- [ ] feature request
Versions.
@angular/cli: 1.4.5
node: 6.11.3
os: win32 x64
@angular/animations: 4.4.4
@angular/common: 4.4.4
@angular/compiler: 4.4.4
@angular/core: 4.4.4
@angular/forms: 4.4.4
@angular/http: 4.4.4
@angular/platform-browser: 4.4.4
@angular/platform-browser-dynamic: 4.4.4
@angular/router: 4.4.4
@angular/cli: 1.4.5
@angular/compiler-cli: 4.4.4
@angular/language-s
Windows 10 Enterprise version 1703
Repro steps.
- Create a new project using
ng new PROJECT-NAME
- Create an
apps
folder inside of thesrc
folder. - Move everything in
src/app
intosrc/apps
, which will result in a file structure ofsrc/apps/app/<component>
- Change the apps root in
.angular-cli.json
to besrc/apps
The final result of executing steps 1 to 4 can be seen here: https://github.com/Feeni/angular-cli-windows
- Attempt to generate a new component using
ng g c test-me -d
- an error will appear statingCould not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.
- Attempt to generate a new component using
ng g c test-me --skip-import -d
- it will do a dry run of the component creation, but the path will besrc/apps/src/apps/<component>
. Notice how the root seems to be duplicated twice.
The log given by the failure.
ng g c test-me -d
Error: Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.
Could not find an NgModule for the new component. Use the skip-import option to skip importing components in NgModule.
ng g c test-me --skip-import -d
create src/apps/src/apps/app/test-me/test-me.component.html (26 bytes)
create src/apps/src/apps/app/test-me/test-me.component.spec.ts (629 bytes)
create src/apps/src/apps/app/test-me/test-me.component.ts (272 bytes)
create src/apps/src/apps/app/test-me/test-me.component.css (0 bytes)
NOTE: Run with "dry run" no changes were made.
NOTE: While there are no errors above, note how the path of src/apps
is being copied twice.
Desired functionality.
We would like to use the Angular CLI to generate components even with a different directory structure on Windows.
Mention any other details that might be useful.
- Our current work-around is to downgrade to
v.1.3.2
, as generating components in Windows works fine in that version. - When attempting to generate components using the repo linked above on a Macbook as well as using Bash on Ubuntu for Windows, it works with no issues.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 27 (2 by maintainers)
Commits related to this issue
- fix(@angular/cli): fix generate app root in windows Fix #7960 — committed to filipesilva/angular-cli by filipesilva 7 years ago
- fix(@angular/cli): fix generate app root in windows Fix #7960 — committed to angular/angular-cli by filipesilva 7 years ago
- fix(@angular/cli): fix generate app root in windows Fix #7960 — committed to angular/angular-cli by filipesilva 7 years ago
- fix(@angular/cli): fix generate app root in windows Fix #7960 — committed to d2clouds/speedray-cli by filipesilva 7 years ago
I had the same problem after upgrading a project from Angular 4.3 to Angular 6. The problem turned out to be the
sourceRoot
value inangular.json
under the[project-name]-e2e
project. It was set to “e2e”. When comparing to other projects created initially with Angular 6 (not upgraded), I noticed that they had an empty string specified forsourceRoot
on the e2e project. After changing mine to that configuration, this problem was resolved.Please note that
sourceRoot
for the primary project should still be “src”, you should only need to change it to an empty string on the e2e project.I’m having the same problem. “Upgraded” to Angular 6, and now I can no longer generate components, services, etc.
“Could not find an NgModule”
A temporary workaround is switching to bash on windows when using
ng generate
.This should really be a highly prioritized bug to fix.
use --skip-import flag to ignore this message because otherwise angular-cli will look for a module to declare the component and if it can’t find it it won’t generate component. try this and it should work.
I am creating a project to support multiple apps and ran into a similar (or perhaps same) scenario. For starters, I’m using @angular/cli@1.5.0-beta.4 (on Windows) since I needed appRoot support. The basic directory structure is similar to .NET Core features where all code is grouped by folders and client code lives right next to server code, which is why appRoot is called Client. I’ve pushed the common Angular config files to the root so they are shared across apps, so the structure is as follows (I’ve obviously left out some files from this listing):
More importantly, here are the associated CLI config values:
When I run the command with --skip-import and dry run, I get the following as others have been observing:
Without skip-import, it’s also unable to track down the module to add it to as a result of the wrong path.
I spent some time adding logging to the angular-cli code and came up with the following findings that I hope will help troubleshoot this: In generate.ts, the run function had the following values: parsedPath value
commandOptions values
When seeing the behavior in find-module.js, it looks like the root problem there is in the way that it builds out the pathToCheck. findModuleFromOptions
pathToCheck logic
resulting pathToCheck value Group1/Feature1/Group1/Feature1/Client/foo
I took a quick look in the component\index.js file that is used to create components and it has similar logic:
I’m not sure what the exact fix is since this code has to support multiple combinations of command option values, but hopefully this helps isolate the issue. Thanks.
So Angular doesn’t currently work on Windows? I’m working through the tutorial and I got stuck here:
I agree with @vilic This should really be fixed ASAP. If some contributor would tell us what info does he need to fix this, I’ll be more than pleased to help him.
I have the same problem after upgrading to Angular 6, same versions as the user above me.
@jeffreymichell facing same issue after upgrading to angular 6. Has anyone able to fix the issue ?
Still having this problem. Cannot generate any components on Windows. Incredibly annoying to deal with.
For now, the best solution for me is explicitly adding import module path:
ng g c moduleName --module='app.module.shared.ts'