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?
@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
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/schematicsif you're on version 8 or later of Nx. Use the@nrwl/angularschematics 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.
Related issue: https://github.com/nrwl/nx/issues/3497
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! 馃檹
Most helpful comment
The fix for this behaviour is to remove
workspace.json.