Nx: extending "@nrwl/schematics"-"lib" produces "Cannot read property 'schematics' of undefined"

Created on 5 Jun 2020  路  6Comments  路  Source: nrwl/nx

Description

We cannot execute the lib schematic when running our own schematic (that is extending the lib schematic) as a node_modules package in another repo. We are getting the error Cannot read property 'schematics' of undefined when this line of code is executed:

externalSchematic("@nrwl/schematics", "lib", {name: "foo", style: "scss"}),

Where exactly, we don't know; there is no stacktrace.

It seems the problem is not with the packaging - we can use our schematic in our main repo from node_modules; only when importing the module via verdaccio in another repo, it occurs.

We tried using "@nrwl/workspace" instead of "@nrwl/schematics" but that fails with Cannot read property 'architect' of undefined

Considering the complicated environment, we can't really provide a minimal example for you to reproduce, but perhaps you have some advice what might be the problem or how to debug this?

Environment

  @nrwl/angular : 8.11.1
  @nrwl/cli : 9.3.0
  @nrwl/cypress : 8.11.1
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 9.3.0
  @nrwl/linter : Not Found
  @nrwl/nest : Not Found
  @nrwl/next : Not Found
  @nrwl/node : Not Found
  @nrwl/react : Not Found
  @nrwl/schematics : 8.12.11
  @nrwl/tao : 9.3.0
  @nrwl/web : Not Found
  @nrwl/workspace : 9.3.0
  typescript : 3.5.3
angular stale question / discussion

Most helpful comment

The fix for this behaviour is to remove workspace.json.

All 6 comments

Extending @philly-vanilly's description:

The custom schematics custom-lib can be boiled down to:

export default function (schema: Schema): Rule {
   return chain([
      externalSchematic("@nrwl/schematics", "lib", normalizedSchema)
      // here we have additional steps, but the error happens in the externalSchematic step
   ]);
};

We then deploy it to an npm registry under @our-company/schematics, and try to call it with:
ng g @our-company/schematics:custom-lib

Then the error happens:
Cannot read property 'schematics' of undefined

@adrianbarwicki you should no longer be using @nrwl/schematics if you're on version 8 or later of Nx. Use the @nrwl/angular schematics instead

@adrianbarwicki you should no longer be using @nrwl/schematics if you're on version 8 or later of Nx. Use the @nrwl/angular schematics instead

Hi @brandonroberts,

thanks for the reply. I changed it from @nrwl/schematics to @nrwl/angular, but unfortunately, the bug Cannot read property 'schematics' of undefined is still present. We are using the version 8.11.1.

Do you have some other tips on how to resolve it or debug it better on our site?

The fix for this behaviour is to remove workspace.json.

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 馃檹

Was this page helpful?
0 / 5 - 0 ratings

Related issues

IonFoXx picture IonFoXx  路  3Comments

about-code picture about-code  路  3Comments

Svancara picture Svancara  路  3Comments

ZempTime picture ZempTime  路  3Comments

joelmuskwe picture joelmuskwe  路  3Comments