Skip to content
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

Invalid path when generating a module inside a sub directory #3063

Closed
neilkyoung opened this issue Nov 8, 2016 · 7 comments · Fixed by #3066
Closed

Invalid path when generating a module inside a sub directory #3063

neilkyoung opened this issue Nov 8, 2016 · 7 comments · Fixed by #3066

Comments

@neilkyoung
Copy link

neilkyoung commented Nov 8, 2016

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.19-3
node: 6.3.0
os: linux x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
N/A

The log given by the failure.

Normally this include a stack trace and some more information.

ng g module shared/some-feature
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
installing module
create src/app/shared/some-feature/some-feature.module.ts
installing component
Invalid path: "/home/vagrant/workspace/ss-angular-cli-starter/src/app/some-feature"" is not a valid path.

Mention any other details that might be useful.

I have tried generating the module with different scenarios in different folder names but the issue persists.


Thanks! We'll be in touch soon.

@Meligy
Copy link
Contributor

Meligy commented Nov 8, 2016

The shared folder was removed from the CLI in #2623.

The problem happens because the shared folder does not exist.

The CLI breaks with error invalid path if there's a folder in the path you provide to the generate command that does not exist (except the path the command generates by itself of course).

So, you'll have to create the src/app/shared folder manually first, then the command will work with no error.

@Meligy
Copy link
Contributor

Meligy commented Nov 8, 2016

I take that back. This is not the same problem.

It's also not #2756, which is about the 2-word component names. It happens with single word names as well.

It seems the shared portion of the path is removed when the CLI is figuring out the path to create the component in. This is shown by the last part of the error message.

> ng g module shared/feature     

Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
installing module
  create src/app/shared/feature/feature.module.ts
installing component
Invalid path: "/Users/Meligy/Code/temp/cli-tests/love-to-share/src/app/feature"" is not a valid path.

@Meligy
Copy link
Contributor

Meligy commented Nov 8, 2016

It's worth mentioning this is NOT shared specific.

I can reproduce it in beta.19-3 as follows:

> mkdir src/app/trying

> ng g module trying/some-module
Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
installing module
  create src/app/trying/some-module/some-module.module.ts
installing component
Invalid path: "/Users/Meligy/Code/temp/cli-tests/love-to-share/src/app/some-module"" is not a valid path.

@neilkyoung neilkyoung changed the title Invalid path when generating a shared module Invalid path when generating a module inside a sub directory Nov 8, 2016
@Meligy
Copy link
Contributor

Meligy commented Nov 8, 2016

For the record: I tried this now against master (f815228 at the moment), and it's still happening in it.

@Meligy
Copy link
Contributor

Meligy commented Nov 8, 2016

I think I found the offending line of code:

https://github.com/angular/angular-cli/blob/master/packages/angular-cli/blueprints/module/index.js#L61

To generate a component, it runs:

  afterInstall: function (options) {
    options.entity.name = path.join(this.dasherizedModuleName, this.dasherizedModuleName);
    options.flat = true;
    options.route = false;
    options.inlineTemplate = false;
    options.inlineStyle = false;
    options.prefix = true;
    options.spec = true;
    return Blueprint.load(path.join(__dirname, '../component')).install(options);
  }

Note this line:

    options.entity.name = path.join(this.dasherizedModuleName, this.dasherizedModuleName);

If you change it to:

    var componentPath = path.join(this.generatePath, this.dasherizedModuleName);    
    options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath);

It works!

@Brocco if this sounds good, I can make the change and add a test in a new PR.

@Meligy
Copy link
Contributor

Meligy commented Nov 8, 2016

OK, so the PR that fixes this was marked as ready for merge.

I'm not 100% sure of the merge frequency in this repo, so for now, the workaround is to ignore the error, and repeat the exact command with component instead of module.

Like:

ng g module parent/child

...

ng g component parent/child

MRHarrison pushed a commit to MRHarrison/angular-cli that referenced this issue Feb 9, 2017
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants