Reputation: 171
When I try to create a new component in my Angular 14.7.13 app by running this code:
/f/JS/apps/myapp/src/app/board (main)
$ npx nx generate @nrwl/angular:component board --project=myapp --style=scss --no-interactive --verbose
I get the following error:
Error: The path provided for the component (src/app/board) does not exist under the project root (). Please make sure to provide a path that exists under the project root.
at checkPathUnderProjectRoot (F:\JS\apps\myapp\node_modules\@nrwl\angular\src\generators\component\component.js:34:15)
at F:\JS\apps\myapp\node_modules\@nrwl\angular\src\generators\component\component.js:14:9
at Generator.next (<anonymous>)
at F:\JS\apps\myapp\node_modules\tslib\tslib.js:118:75
at new Promise (<anonymous>)
at Object.__awaiter (F:\JS\apps\myapp\node_modules\tslib\tslib.js:114:16)
at componentGenerator (F:\JS\apps\myapp\node_modules\@nrwl\angular\src\generators\component\component.js:11:20)
at Object.<anonymous> (F:\JS\apps\myapp\node_modules\nx\src\command-line\generate.js:250:36)
at Generator.next (<anonymous>)
at fulfilled (F:\JS\apps\myapp\node_modules\tslib\tslib.js:115:62)
I am in the folder where I want the 'board' component to be.
It makes no difference if I run it in the project root which is /f/js/apps/myapp/ as I get the same error.
This seems to be a known issue as per this thread: https://github.com/nrwl/nx/issues/12042. See comment:
While waiting for the fix to be published, you can still generate the component by specifying the --project flag with the project name where the component is going to be generated. The fix removes this requirement when a path is provided.
But I am running --project=myapp?
Can anyone tell me if they're aware of a fix for this issue, please?
Upvotes: 3
Views: 3692
Reputation: 66
A solution to this is to edit the "root" property in angular.json
, which should be placed in the root folder of your project.
Change its line from
"root": "",
to
"root": "./src",
This will allow you to create new Components in your src/app folder.
Upvotes: 4