#Can't generate component after migrating to a new version of nx

1 messages · Page 1 of 1 (latest)

nimble tulip
#

On my project my team has upgraded nx from v14 to v16. I'm trying to generate a new component with updated CLI commands provided by nx here: https://nx.dev/nx-api/angular/generators/component

When I run it like this npx nx g @nx/angular:component --name=my-component --directory=./apps/my-app/src/app --nameAndDirectoryFormat=derived I receive an error from nx 'directory' is not found in schema.

When I try to call the barebones nx wizard via npx nx g @nx/angular:component, after I have provided the name of the component in the wizard, I get NX: Cannot read properties of undefined (reading 'find').

Does anyone know what can be wrong with the setup?

Nx

Creates a new Angular component.

nimble tulip
#

After some digging, I see that the root cause might be that when nx is trying to create a component, it passes the data about module to ts auxiliary functions in a process to extract decorators from the node, specifically canHaveDecorators

When it does so, the method canHaveDecorators tries to understand whether a node can have a decorator, specifically in this piece of logic

    function canHaveDecorators(node) {
        var kind = node.kind;
        return kind === 166 /* SyntaxKind.Parameter */
            || kind === 169 /* SyntaxKind.PropertyDeclaration */
            || kind === 171 /* SyntaxKind.MethodDeclaration */
            || kind === 174 /* SyntaxKind.GetAccessor */
            || kind === 175 /* SyntaxKind.SetAccessor */
            || kind === 228 /* SyntaxKind.ClassExpression */
            || kind === 260 /* SyntaxKind.ClassDeclaration */;
    }
    ts.canHaveDecorators = canHaveDecorators;

In my case the node kind turns out to be 262 which breaks all the upstream logic. It seems to be some bug in how nx sets the component up, but I'm not sure

placid pumice
#

Nx mostly delegates to the angular schematics, could be a version compatibility issue?