Repository navigation
Creating a project with existing directory => impossible? #9655
Description
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:
- Adding angular-cli to existing project? On using ng init #755
- Provide a way to generate a new project in an existing directory #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":"angular-cli@angular.io"},"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":"angular-cli@angular.io"},"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"
Activity
clydin commentedon Feb 16, 2018
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.sokraflex commentedon Feb 16, 2018
Unfortunately, when calling
--directory ., the error message stays the same:sokraflex commentedon Feb 16, 2018
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:
it works fine. However, the original case fails with the described error message:
And the following new test case fails as well, but with a new error message:
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.
clydin commentedon Feb 16, 2018
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?sokraflex commentedon Feb 16, 2018
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.clydin commentedon Feb 16, 2018
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.
Krumpet commentedon Feb 18, 2018
I also encountered this problem: trying to create from within the project folder with
--directory .failed with the error described above, as didcdng new name --directory ./subdirectorybut this worked (without the dot):
cdng new name --directory subdirectorycolmben commentedon Feb 23, 2018
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.fix: Remove --dir options for the 'new' generator. See angular/angula…
jmussman commentedon Feb 24, 2018
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.
denofevil commentedon Feb 26, 2018
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.
granite commentedon Feb 27, 2018
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
Gaspa79 commentedon Feb 27, 2018
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
18 remaining items
kay17 commentedon Jun 19, 2018
I could resolve the error by changing
ng new test_essentials
to
ng new essentials
Apart from numbers in the name, apparently an underscore is not accepted either
NDMCreative commentedon Jul 17, 2018
ng new does not like the underscore " _ " so test_essentials should be put down as testEssentials
arledesma commentedon Jul 31, 2018
This functionality is also hit and miss across all 6.x versions
Tested with the following:
versions and output
output:
$ ng new ngCli600 --directory=./ -d Schematic input does not validate against the Schema: {"dryRun":true,"directory":"./","skipGit":true,"version":"6.0.0","skipInstall":false,"linkCli":false,"commit":true,"newProjectRoot":"projects","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","style":"css","skipTests":false} Errors: Data path ".directory" should match format "path".output:
$ ng new ngCli601 --directory=./ -d Schematic input does not validate against the Schema: {"dryRun":true,"directory":"./","skipGit":true,"version":"6.0.1","skipInstall":false,"linkCli":false,"commit":true,"newProjectRoot":"projects","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","style":"css","skipTests":false} Errors: Data path ".directory" should match format "path".output:
$ ng new ngCli602 --directory=./ -d CREATE README.md (1025 bytes) CREATE angular.json (3420 bytes) CREATE package.json (1313 bytes) CREATE tsconfig.json (384 bytes) CREATE tslint.json (2805 bytes) CREATE .editorconfig (245 bytes) CREATE .gitignore (503 bytes) CREATE src/environments/environment.prod.ts (51 bytes) CREATE src/environments/environment.ts (631 bytes) CREATE src/favicon.ico (5430 bytes) CREATE src/index.html (295 bytes) CREATE src/main.ts (370 bytes) CREATE src/polyfills.ts (3194 bytes) CREATE src/test.ts (642 bytes) CREATE src/assets/.gitkeep (0 bytes) CREATE src/styles.css (80 bytes) CREATE src/browserslist (375 bytes) CREATE src/karma.conf.js (964 bytes) CREATE src/tsconfig.app.json (194 bytes) CREATE src/tsconfig.spec.json (282 bytes) CREATE src/tslint.json (314 bytes) CREATE src/app/app.module.ts (314 bytes) CREATE src/app/app.component.css (0 bytes) CREATE src/app/app.component.html (1141 bytes) CREATE src/app/app.component.spec.ts (986 bytes) CREATE src/app/app.component.ts (207 bytes) CREATE e2e/protractor.conf.js (752 bytes) CREATE e2e/src/app.e2e-spec.ts (299 bytes) CREATE e2e/src/app.po.ts (208 bytes) CREATE e2e/tsconfig.e2e.json (213 bytes) NOTE: Run with "dry run" no changes were made.output:
$ ng new ngCli603 --directory=./ -d CREATE README.md (1025 bytes) CREATE angular.json (3420 bytes) CREATE package.json (1313 bytes) CREATE tsconfig.json (384 bytes) CREATE tslint.json (2805 bytes) CREATE .editorconfig (245 bytes) CREATE .gitignore (503 bytes) CREATE src/environments/environment.prod.ts (51 bytes) CREATE src/environments/environment.ts (631 bytes) CREATE src/favicon.ico (5430 bytes) CREATE src/index.html (295 bytes) CREATE src/main.ts (370 bytes) CREATE src/polyfills.ts (3194 bytes) CREATE src/test.ts (642 bytes) CREATE src/assets/.gitkeep (0 bytes) CREATE src/styles.css (80 bytes) CREATE src/browserslist (375 bytes) CREATE src/karma.conf.js (964 bytes) CREATE src/tsconfig.app.json (194 bytes) CREATE src/tsconfig.spec.json (282 bytes) CREATE src/tslint.json (314 bytes) CREATE src/app/app.module.ts (314 bytes) CREATE src/app/app.component.css (0 bytes) CREATE src/app/app.component.html (1141 bytes) CREATE src/app/app.component.spec.ts (991 bytes) CREATE src/app/app.component.ts (207 bytes) CREATE e2e/protractor.conf.js (752 bytes) CREATE e2e/src/app.e2e-spec.ts (299 bytes) CREATE e2e/src/app.po.ts (208 bytes) CREATE e2e/tsconfig.e2e.json (213 bytes) NOTE: Run with "dry run" no changes were made.output:
$ ng new ngCli604 --directory=./ -d Schematic input does not validate against the Schema: {"dryRun":true,"directory":"./","skipGit":true,"version":"6.0.4","skipInstall":false,"linkCli":false,"commit":true,"newProjectRoot":"projects","inlineStyle":false,"inlineTemplate":false,"routing":false,"prefix":"app","style":"css","skipTests":false} Errors: Data path "" should NOT have additional properties(dryRun).output:
$ ng new ngCli605 --directory=./ -d CREATE README.md (1025 bytes) CREATE angular.json (3420 bytes) CREATE package.json (1313 bytes) CREATE tsconfig.json (384 bytes) CREATE tslint.json (2805 bytes) CREATE .editorconfig (245 bytes) CREATE .gitignore (503 bytes) CREATE src/environments/environment.prod.ts (51 bytes) CREATE src/environments/environment.ts (631 bytes) CREATE src/favicon.ico (5430 bytes) CREATE src/index.html (295 bytes) CREATE src/main.ts (370 bytes) CREATE src/polyfills.ts (3194 bytes) CREATE src/test.ts (642 bytes) CREATE src/assets/.gitkeep (0 bytes) CREATE src/styles.css (80 bytes) CREATE src/browserslist (375 bytes) CREATE src/karma.conf.js (964 bytes) CREATE src/tsconfig.app.json (194 bytes) CREATE src/tsconfig.spec.json (282 bytes) CREATE src/tslint.json (314 bytes) CREATE src/app/app.module.ts (314 bytes) CREATE src/app/app.component.css (0 bytes) CREATE src/app/app.component.html (1141 bytes) CREATE src/app/app.component.spec.ts (991 bytes) CREATE src/app/app.component.ts (207 bytes) CREATE e2e/protractor.conf.js (752 bytes) CREATE e2e/src/app.e2e-spec.ts (299 bytes) CREATE e2e/src/app.po.ts (208 bytes) CREATE e2e/tsconfig.e2e.json (213 bytes) NOTE: Run with "dry run" no changes were made.output:
$ ng new ngCli607 --directory=./ -d CREATE README.md (1025 bytes) CREATE angular.json (3566 bytes) CREATE package.json (1313 bytes) CREATE tsconfig.json (384 bytes) CREATE tslint.json (2805 bytes) CREATE .editorconfig (245 bytes) CREATE .gitignore (503 bytes) CREATE src/environments/environment.prod.ts (51 bytes) CREATE src/environments/environment.ts (631 bytes) CREATE src/favicon.ico (5430 bytes) CREATE src/index.html (295 bytes) CREATE src/main.ts (370 bytes) CREATE src/polyfills.ts (3194 bytes) CREATE src/test.ts (642 bytes) CREATE src/assets/.gitkeep (0 bytes) CREATE src/styles.css (80 bytes) CREATE src/browserslist (375 bytes) CREATE src/karma.conf.js (964 bytes) CREATE src/tsconfig.app.json (194 bytes) CREATE src/tsconfig.spec.json (282 bytes) CREATE src/tslint.json (314 bytes) CREATE src/app/app.module.ts (314 bytes) CREATE src/app/app.component.css (0 bytes) CREATE src/app/app.component.html (1141 bytes) CREATE src/app/app.component.spec.ts (991 bytes) CREATE src/app/app.component.ts (207 bytes) CREATE e2e/protractor.conf.js (752 bytes) CREATE e2e/src/app.e2e-spec.ts (304 bytes) CREATE e2e/src/app.po.ts (208 bytes) CREATE e2e/tsconfig.e2e.json (213 bytes) NOTE: Run with "dry run" no changes were made.output:
$ ng new ngCli608 --directory=./ -d CREATE README.md (1025 bytes) CREATE angular.json (3566 bytes) CREATE package.json (1313 bytes) CREATE tsconfig.json (384 bytes) CREATE tslint.json (2805 bytes) CREATE .editorconfig (245 bytes) CREATE .gitignore (503 bytes) CREATE src/environments/environment.prod.ts (51 bytes) CREATE src/environments/environment.ts (631 bytes) CREATE src/favicon.ico (5430 bytes) CREATE src/index.html (295 bytes) CREATE src/main.ts (370 bytes) CREATE src/polyfills.ts (3194 bytes) CREATE src/test.ts (642 bytes) CREATE src/assets/.gitkeep (0 bytes) CREATE src/styles.css (80 bytes) CREATE src/browserslist (375 bytes) CREATE src/karma.conf.js (964 bytes) CREATE src/tsconfig.app.json (194 bytes) CREATE src/tsconfig.spec.json (282 bytes) CREATE src/tslint.json (314 bytes) CREATE src/app/app.module.ts (314 bytes) CREATE src/app/app.component.css (0 bytes) CREATE src/app/app.component.html (1141 bytes) CREATE src/app/app.component.spec.ts (991 bytes) CREATE src/app/app.component.ts (207 bytes) CREATE e2e/protractor.conf.js (752 bytes) CREATE e2e/src/app.e2e-spec.ts (304 bytes) CREATE e2e/src/app.po.ts (208 bytes) CREATE e2e/tsconfig.e2e.json (213 bytes) NOTE: Run with "dry run" no changes were made.output:
$ ng new ngCli610 --directory=./ -d Path "/README.md" already exist.output:
$ ng new ngCli611 --directory=./ -d Path "/README.md" already exist.HASSAANALVI20 commentedon Aug 14, 2018
please help angular 5 project not create using ng new myapp .project stop successfully initialized git
Parth7030 commentedon Nov 28, 2022
With Latest angular version I guess from V12 you can use:
ng generate application <name> [options]alan-agius4 commentedon Aug 28, 2026
Thanks for reporting this issue. Please update to the most recent version to resolve the problem.
If the problem persists in your application after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior. You can use
ng new repro-appto create a new project where you reproduce the problem.angular-automatic-lock-bot commentedon Oct 20, 2026
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.