nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.28k stars 2.32k forks source link

Creating a new workspace failed with error #531

Closed jared-christensen closed 6 years ago

jared-christensen commented 6 years ago

Im setting up a new project and following the docs found here https://nrwl.io/nx/guide-nx-workspace

When I run ng new myworkspacename --collection=@nrwl/schematics

I get this error.

Could not find module "@ngrx/schematics" from "/Users/jaredc/Repositories/nx-test".
Error: Could not find module "@ngrx/schematics" from "/Users/jaredc/Repositories/nx-test".
    at Object.resolve (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at NodeModulesEngineHost._resolvePackageJson (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:29:21)
    at NodeModulesEngineHost._resolveCollectionPath (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:70:40)
    at NodeModulesEngineHost.createCollectionDescription (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:106:27)
    at SchematicEngine._createCollectionDescription (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:78:40)
    at SchematicEngine._createCollectionDescription (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:89:48)
    at SchematicEngine.createCollection (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/schematics/src/engine/engine.js:71:43)
    at Object.getCollection (/usr/local/lib/node_modules/@angular/cli/utilities/schematics.js:28:31)
    at NewCommand.getOptions (/usr/local/lib/node_modules/@angular/cli/models/schematic-command.js:193:41)
    at NewCommand.initialize (/usr/local/lib/node_modules/@angular/cli/commands/new.js:48:21)

I have these globally

/usr/local/lib
├── @angular/cli@6.0.5
├── @nrwl/schematics@6.0.2
└── npm@6.1.0
martzcodes commented 6 years ago

I just created a fresh workspace and it worked fine. Did you run it in a clean / empty directory? Maybe try reinstalling @angular/cli and @nrwl/schematics?

jlmonteagudo commented 6 years ago

I get the same error, and previously I uninstalled @nrwl/schematics and installed it again.

b-johnse commented 6 years ago

Similar issue, created a new workspace following the docs and it just gave me a blank angular cli project not a workspace and also wouldnt take the ng add

jared-christensen commented 6 years ago

I just got it to work when I added an @ before collection. ng new myworkspacename --@collection=@nrwl/schematics

I think the docs maybe have a typo.

No @ on this page https://nrwl.io/nx/guide-nx-workspace ng new myworkspacename --collection=@nrwl/schematics

With @ on this page https://nrwl.io/nx/guide-getting-started ng new myworkspacename --@collection=@nrwl/schematics

What is really confusing is it looks like it should not need the @ according to issue #506

martzcodes commented 6 years ago

Ah, i used the @ which is why it worked for me.

I also noticed that the docs say to use ng g app (which doesn't work) when it's supposed to be ng g application ... so, heads up for that

Edit: Just noticed... using the @ didn't in-fact work... it just used the default angular-cli and no error was thrown. Does angular-cli support mono-repos now by default?

texel commented 6 years ago

It works with ng new myworkspacename --@collection=@nrwl/schematics but that's because --@collection isn't a valid option so it just ignores it and generates a new ng workspace without any of the nx schematics.

I got it to work by globally installing @ngrx/schematics as well, but then when I tried to generate the workspace it did it in the current directory instead of creating a new directory.

Basically, right now both the docs and the tooling for creating a new nx workspace are broken.

[edit] but running $ npx create-nx-workspace app-name seems to work fine

martzcodes commented 6 years ago

@texel I thought the same too, but I don't think it's using it even when globally installed. (see my updated comment)

Generating a project with angular-cli by itself seems to support applications / libraries now by default

martzcodes commented 6 years ago

ng new myworkspacename --collection=@nrwl/schematics also works... the @ in front of collection was the problem. https://nrwl.io/nx/guide-getting-started should get updated to remove it.

Back to the original issue... I was able to get it to work with the above command and it generated the file structure I was expecting without any errors.

(I'm going to shut up now)

FrozenPandaz commented 6 years ago

Hey guys,

Sorry for the delayed response. I did some lengthy investigation.

The proper command should indeed be:

ng new workspace --collection=@nrwl/schematics

We will update our documentation.

As you folks have found, there are the following two issues with creating a new Nx Workspace.

Workspaces are created in the working directory, not in their own directory

Re: @texel

@angular/cli seems to have a regression. If you are using @angular/cli@6.0.1 you should not have this issue

ng new cannot find @ngrx/schematics

@angular/cli cannot resolve our dependency on @ngrx/schematics. You can help it by installing it yourself.

sudo npm i @ngrx/schematics -g
mehulgupta29 commented 6 years ago

ng new workspace --collection=@nrwl/schematics still does not work for me.

pri17 commented 5 years ago

https://stackoverflow.com/questions/56832774/nx-workspace-cli-does-not-allow-to-create-pure-typescript-library-since-version

Found this, by running "ng add @nrwl/node" resolve this issue for unknown reason lol.

pri17 commented 5 years ago

ng new workspace --collection=@nrwl/schematics still does not work for me.

same, feels like this issue close very soon.....

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.