Home > other >  generating new nestjs module results in Error: Failed to execute command
generating new nestjs module results in Error: Failed to execute command

Time:06-24

I'm using MacOS monterey with M1 chip as my operating system. installed NestJS cli using this command: sudo npm install -g @nestjs/cli

when creating new nest project using nest new message everything works fine, but when I try to create new module using this command nest generate module messages I face error.

why does this happen? I tried installing schematics using npm i -g @nestjs/schematics, I don't know if I should've installed it but this didn't help anyway.

The error I face is:

/Users/homayoun/training/messages/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:338
            throw new Error(`Unknown argument ${key}. Did you mean ${(0, yargs_parser_1.decamelize)(key)}?`);
                  ^

Error: Unknown argument skipImport. Did you mean skip-import?
    at parseArgs (/Users/homayoun/training/messages/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:338:19)
    at main (/Users/homayoun/training/messages/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:122:49)
    at Object.<anonymous> (/Users/homayoun/training/messages/node_modules/@angular-devkit/schematics-cli/bin/schematics.js:367:5)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

Failed to execute command: node @nestjs/schematics:module --name=messages --no-dry-run --no-skipImport --language="ts" --sourceRoot="src" --spec.

worth noting that I don't face any issues when I do the same thing on ubuntu 20 or 22

CodePudding user response:

Quick solution:

  1. add this to your nest-cli.json
"root": "src"
  1. change into the src of your project folder
cd src
  1. run
nest generate module messages

if the above does not work also try changing the version of packages in package.json to

"@nestjs/cli": "8.2.6",
"@nestjs/schematics": "8.0.11",

removing the node modules in the current project reinstalling the nest cli with

npm uninstall -g @nestjs/cli
npm i -g @nestjs/[email protected] 

CodePudding user response:

this is a bug on the latest version of @nestjs/cli (v8.2.7). Downgrade it to 8.2.6 and it will work (I tested it). It was reported here: https://github.com/nestjs/nest-cli/issues/1693

Also, I don't recommend using the global version of the CLI. Instead, use npx nest or yarn nest.

  • Related