Skip to content

ng generate component fails #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
doczoidberg opened this issue Mar 12, 2016 · 13 comments · Fixed by #310
Closed

ng generate component fails #297

doczoidberg opened this issue Mar 12, 2016 · 13 comments · Fixed by #310
Assignees

Comments

@doczoidberg
Copy link

I created a new project with the latest angular-cli npm packages 0.0.25 and can't generate a component?

c:\temp\app5>ng generate component comp1
installing component
Cannot read property 'indexOf' of undefined
TypeError: Cannot read property 'indexOf' of undefined
    at Class.module.exports.normalizeEntityName (c:\temp\app5\node_modules\angular-cli\addon\ng2\blueprints\component\index.js:19:19)
    at Class.Blueprint._normalizeEntityName (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\lib\models\blueprint.js:434:24)
    at Class.Blueprint.install (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\lib\models\blueprint.js:492:8)
    at Class.module.exports.Task.extend.run (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\lib\tasks\generate-from-blueprint.js:60:49)
    at Class.module.exports.Command.extend.run (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\lib\commands\generate.js:77:17)
    at Class.<anonymous> (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\lib\models\command.js:151:17)
    at lib$rsvp$$internal$$tryCatch (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1036:16)
    at lib$rsvp$$internal$$invokeCallback (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1048:17)
    at c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:331:11
    at lib$rsvp$asap$$flush (c:\temp\app5\node_modules\angular-cli\node_modules\angular-cli\node_modules\rsvp\dist\rsvp.js:1198:9)
@filipesilva
Copy link
Contributor

That is quite problematic! I went to check and on the latest master, I believe the issue is solved.

@Brocco reworked the way components are generated to allow for dynamic paths. I expect this to be fixed on the next release.

For now, my only solution is to use latest master though.

@filipesilva
Copy link
Contributor

My mistake, I just tried it on the windows cmd prompt and had the same problem on latest master.

@Brocco
Copy link
Contributor

Brocco commented Mar 12, 2016

@doczoidberg can you please clarify which version of the CLI you're using/

@doczoidberg
Copy link
Author

@Brocco 0.0.25

Brocco added a commit to Brocco/angular-cli that referenced this issue Mar 12, 2016
Windows does not populate  this fix allows for determination
of the directory from which an ng command was executed
Fixes angular#297
@markjritchie
Copy link

Changing from line 17 of index.js to
if (entityName.indexOf(path.sep) === 0) {
outputPath = path.join(rootPath, entityName.substr(1));
} else if (cwd && cwd.indexOf(rootPath) >= 0) {
outputPath = path.join(cwd, entityName);
} else if (cwd && cwd.indexOf(path.join(this.project.root, 'src')) >= 0
&& entityName.indexOf('app') === 0) {
outputPath = path.join(cwd, entityName);
} else if (cwd && cwd.indexOf(path.join(this.project.root, 'src')) >= 0) {
outputPath = path.join(cwd, 'app', entityName);
}

Is a good workaround for me just now

@Brocco
Copy link
Contributor

Brocco commented Mar 14, 2016

@markjritchie that will allow you to get by for now, except it will not allow you to utilize the purpose of this feature, which is to generate items into a dynamic path and also allow routes to be based upon a relative path (current working directory)

@markjritchie
Copy link

@Brocco very true, but I thought it might be handy to post for anybody that's stuck waiting for the next release

@pierreboissinot
Copy link

I've the same problem on a Windows Environment, is this a Windows problem only ? Does it work on a Linux System like Mac ?

@filipesilva
Copy link
Contributor

@pierreboissinot It's a windows cmd console specific issue. Which is to say, works on linux and windows with gitbash just fine. We'll fix it.

Brocco added a commit to Brocco/angular-cli that referenced this issue Mar 18, 2016
Windows does not populate  this fix allows for determination
of the directory from which an ng command was executed
Fixes angular#297
Brocco added a commit to Brocco/angular-cli that referenced this issue Mar 18, 2016
Windows does not populate  this fix allows for determination
of the directory from which an ng command was executed
Fixes angular#297
@qasimraza1979
Copy link

qasimraza1979 commented May 31, 2017

getting the following error when run

$ ng generate component people
module.js:471
throw err;
^

Error: Cannot find module '@ngtools/json-schema'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (C:\Users\raza\AppData\Roaming\npm\node_modules@angular\cli\models\config\config.js:6:23)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

ng generate component myComponent

Any one there to help ?

@doczoidberg
Copy link
Author

which version? does it work on a clean project?

@qasimraza1979
Copy link

qasimraza1979 commented May 31, 2017 via email

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants