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

Creating a project with existing directory => impossible?

Open sokraflex opened this issue 8 years ago • 35 comments

Versions

ng --version: 1.7.0 npm --version: 5.0.3 node --version: v6.9.5 OS: Windows 10, 64-bit

Repro steps

  • Create a new project folder: $ mkdir test
  • Switch into the folder: $ cd test
  • Install angular-cli: $ npm install -g @angular/cli
  • Try to create a new angular project with the currenct directory: $ ng new appName --directory ./

The last step is nowhere officially documented, however, multiple GitHub-issues linked to this, including:

  • https://github.com/angular/angular-cli/issues/755
  • https://github.com/angular/angular-cli/issues/5431

In lack of a documented possibility to create an angular project in an existing directory, I used the above solution.

Observed behavior

Error: Schematic input does not validate against the Schema: {"directory":"./","name":"appName","skipGit":false,"style":"css","version":"1.7.0","commit":{"message":"chore: initial commit from @angular/cli\n\n    _                      _                 ____ _     ___\n   / \\   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|\n  / △ \\ | '_ \\ / _\\` | | | | |/ _\\` | '__|   | |   | |    | |\n / ___ \\| | | | (_| | |_| | | (_| | |      | |___| |___ | |\n/_/   \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_|       \\____|_____|___|\n               |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false}
Errors:
  .directory should match format "path"
Schematic input does not validate against the Schema: {"directory":"./","name":"appName","skipGit":false,"style":"css","version":"1.7.0","commit":{"message":"chore: initial commit from @angular/cli\n\n    _                      _                 ____ _     ___\n   / \\   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|\n  / △ \\ | '_ \\ / _\\` | | | | |/ _\\` | '__|   | |   | |    | |\n / ___ \\| | | | (_| | |_| | | (_| | |      | |___| |___ | |\n/_/   \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_|       \\____|_____|___|\n               |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false}
Errors:
  .directory should match format "path"

(Yes, the command results in exactly above output - the error message is repeated twice)

Desired behavior

I would expect that angular generates files for a project in the folder, and of course no error message resulting. The files should be located directly in the "test"-folder and not be placed in a subfolder, e.g. "test/appName".

Mention any other details that might be useful (optional)

Using an absolute path instead of a relatively one (in the ng new command) does not change anything, apart from the path-contents of the error message.

Using the command like $ ng new appName --directory . (without the / in the directory path) results in the same error.

Trying to reference the directory from itself by relative path (used as possible workaround) fails with a new error message:

$ mkdir test
$ cd test
$ ng new appName --directory "../test"
Error: Path "/../test" is invalid.
Path "/../test" is invalid.

If there is any other information I might help you with, please tell me.

Workaround

The same result can be achieved by changing into the parent directory and commanding angular to create the app in the sub-directory:

$ mkdir test
$ ng new appName --directory "test"

sokraflex avatar Feb 16 '18 19:02 sokraflex

Unfortunately, the error messaging is currently overly verbose and repeats. There is on ongoing work to improve the error messaging. In this case the the validation is also overly strict and the actual cause is the / in the --directory ./ option. Removing it should prevent the validation error.

clydin avatar Feb 16 '18 21:02 clydin

Unfortunately, when calling --directory ., the error message stays the same:

C:\Users\MyUser\test>ng new appName --directory .
Error: Schematic input does not validate against the Schema: {"directory":".","name":"appName","skipGit":false,"style":"css","version":"1.7.0","commit":{"message":"chore: initial commit from @angular/cli\n\n    _                      _                 ____ _     ___\n   / \\   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|\n  / △ \\ | '_ \\ / _\\` | | | | |/ _\\` | '__|   | |   | |    | |\n / ___ \\| | | | (_| | |_| | | (_| | |      | |___| |___ | |\n/_/   \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_|       \\____|_____|___|\n               |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false}
Errors:
  .directory should match format "path"

sokraflex avatar Feb 16 '18 21:02 sokraflex

I just gave it another run and I found out that it works if I use a relative path out of a parent directory.

Meaning, when executing the command like this:

$ mkdir test
$ ng new appName --directory "test"

it works fine. However, the original case fails with the described error message:

$ mkdir test
$ cd test
$ ng new appName --directory ./

And the following new test case fails as well, but with a new error message:

$ mkdir test
$ cd test
$ ng new appName --directory "../test"
Error: Path "/../test" is invalid.
Path "/../test" is invalid.

It seems like there are some problems with path resolving?

I'll update my original post to include the workaround for people that land here by google or similar.

sokraflex avatar Feb 16 '18 21:02 sokraflex

You're right. Both . and ./ should work but it appears only an absolute path seems to work. Would you mind trying it with an absolute path to confirm?

clydin avatar Feb 16 '18 21:02 clydin

As already stated in my original post, absolute paths do not work. I tried it with both \ and / notation, only referencing a relative path to a subfolder seems to work.

sokraflex avatar Feb 16 '18 21:02 sokraflex

Absolutes paths work on Mac and linux; the windows drive letter appears to be the problem in that scenario. The initial errors are due to validation of the string argument. The last issue described is actually an unrelated, different issue with an origin in the initialization of the schematic engine.

clydin avatar Feb 16 '18 23:02 clydin

I also encountered this problem: trying to create from within the project folder with --directory . failed with the error described above, as did cd ng new name --directory ./subdirectory

but this worked (without the dot): cd ng new name --directory subdirectory

Krumpet avatar Feb 18 '18 14:02 Krumpet

Just to confirm that absolute paths are NOT working on Ubuntu. Both a root (/) and a home (¬) path don't give the error but actually create a sub-path equivalent to the absolute path underneath the current directory (!). So if you are in /myProject/testProject and you do ng new --dir=/myProject/testProject, it actually creates the project files in /myProject/testProject/myProject/testProject.

colmben avatar Feb 23 '18 12:02 colmben

This is a serious issue that was created with the 1.7.0 release.

Some companies have very restricted environments and installing @angular/cli globally is not an option. In other environments programmers work on multiple projects. How @angular/cli creates files could change as versions of @angular change, and installing @angular/cli globally may force the programmer into a version that is not backwards compatible for old projects.

Up to version 1.6.8 you could install @angular/cli locally in the project folder and then create the project in the same folder with "--directory ." Somebody added path checking to 1.7.0, and it refused to allow . or .. in the path name. This functionality needs to be restored ASAP.

jmussman avatar Feb 24 '18 01:02 jmussman

Seems to be caused by incorrect path validation here. Validation checks whether path equals to its normalised version which trims relative things like .. WebStorm project generation is broken due to this.

denofevil avatar Feb 26 '18 12:02 denofevil

I just ran into this on Windows 8.1 using latest Webstorm using their 'New Project' which creates with angular-cli.

"C:\Program Files\nodejs\node.exe" C:\Users\granite\AppData\Roaming\npm\node_modules@angular\cli\bin\ng new Testing123 --dir=. Schematic input does not validate against the Schema: {"directory":".","name":"Testing123","skipGit":false,"style":"css","version":"1.7.1","commit": SNIP____

Errors:Errors:

.directory should match format "path" .directory should match format "path"

Done

granite avatar Feb 27 '18 05:02 granite

I can confirm that neither relative nor absolute paths are currently working in Windows 10 now. I've done this in the past successfully. Seems to me that the latest update broke it.

I thought I was crazy until I found this

Gaspa79 avatar Feb 27 '18 16:02 Gaspa79

Me too, I'm using with IntelliJ IDEA. The solution is open the terminal and create manually. Not so hard to continue.

ghost avatar Feb 27 '18 22:02 ghost

I have the same issue with @aslthiago .

yelfeng avatar Feb 28 '18 00:02 yelfeng

same as @aslthiago here in IntellijIdea

stiofand avatar Mar 01 '18 07:03 stiofand

ng-cli version 1.7.1 node version 8.9.4 LTS the same issue when i using Intelli IDEA to create angular project

D:\bin\nodejs\node.exe C:\Users\shalk\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng new first-app --dir=. Error: Schematic input does not validate against the Schema: {"directory":".","name":"first-app","skipGit":false,"style":"css","version":"1.7.1","commit":{"message":"chore: initial commit from @angular/cli\n\n _ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _\\ | | | | |/ _\ | '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false} Schematic input does not validate against the Schema: {"directory":".","name":"first-app","skipGit":false,"style":"css","version":"1.7.1","commit":{"message":"chore: initial commit from @angular/cli\n\n _ _ ____ _ ___\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\n / △ \\ | '_ \\ / _\\ | | | | |/ _\| '__| | | | | | |\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\n/_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\n |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false} Errors: Errors: .directory should match format "path" .directory should match format "path" Done

shalk avatar Mar 01 '18 09:03 shalk

Webstorm 2017.3.4

Angular CLI: 1.7.2 Node: 9.7.0 OS: linux x64

/usr/bin/node /usr/lib/node_modules/@angular/cli/bin/ng new untitled --dir=. Error: Schematic input does not validate against the Schema: {"directory":".","name":"untitled","skipGit":false,"style":"css","version":"1.7.2","commit":{"message":"chore: initial commit from @angular/cli\n\n _ _ ____ _ \n / \ _ __ __ _ _ | | __ _ _ __ / | | | |\n / △ \ | ' \ / _\ | | | | |/ _\\ | '| | | | | | |\n / ___ \| | | | (| | || | | (| | | | || |_ | |\n// \\| ||\, |\,||\,|| \____|||\n |/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false} Errors: .directory should match format "path" Schematic input does not validate against the Schema: {"directory":".","name":"untitled","skipGit":false,"style":"css","version":"1.7.2","commit":{"message":"chore: initial commit from @angular/cli\n\n _ _ ____ _ \n / \ _ __ __ _ _ | | __ _ _ __ / | | | |\n / △ \ | ' \ / _\ | | | | |/ _\\ | '| | | | | | |\n / ___ \| | | | (| | || | | (| | | | || |__ | |\n// \\| ||\, |\,||\,|| \____|||\n |___/\n","name":"Angular CLI","email":"[email protected]"},"path":"app","sourceDir":"src","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","skipTests":false,"skipInstall":false,"linkCli":false,"minimal":false,"serviceWorker":false} Errors: .directory should match format "path" Done

jacsonlinux avatar Mar 02 '18 01:03 jacsonlinux

Angular 6.0.0 beta 4 is also failing with this.

F0rt1s avatar Mar 02 '18 16:03 F0rt1s

SargTeX: You labeled this issue as a feature request, but it's definitely a bug. Or a feature that someone thought we needed, but is impeding a significant number of people. Can you relabel as a bug, and maybe freq:high so that someone will notice and address it?

jmussman avatar Mar 04 '18 23:03 jmussman

Hi @clydin, @Brocco, @hansl! As @denofevil has already mentioned in his comment, due to the path validation issue it is now impossible to create a new Angular project in WebStorm and other JetBrains IDEs using Angular CLI 1.7.0. The IDE creates a project directory first and only then runs angular-cli in it – that is something we can’t easily change. What can be done to solve the issue? We really hope that it would be possible again to create Angular projects in WebStorm. Thanks!

prigara avatar Mar 05 '18 17:03 prigara