Code Monkey home page Code Monkey logo

Comments (2)

Rmannn avatar Rmannn commented on June 10, 2024 1

Thx for the report. Will check it soon.

from nestjs-console.

ndtuan412 avatar ndtuan412 commented on June 10, 2024

Maybe I also encounter the same error. Pls guide me if there is wrong in my setup. Thanks.

My setup is:

package.json

{
...
  "scripts": {
    "build": "tsc -p tsconfig.build.json",
    "console:dev": "ts-node -r tsconfig-paths/register src/console.ts",
    "console": "node dist/console.js"
  },
  "dependencies": {
    "@nestjs/common": "^6.0.0",
    "@nestjs/core": "^6.0.0",
    "@nestjs/platform-express": "^6.0.0",
    "nestjs-console": "^1.0.1",
  },
...
}

src/console.ts

import { BootstrapConsole } from 'nestjs-console';
import { Logger } from '@nestjs/common';
import { SampleModule } from './sample/sample.module';

const logger = new Logger('console');

BootstrapConsole
  .init({ module: SampleModule })
  .then(({ app, boot }) => {
    // do something with your app container if you need (app)
    // boot the cli
    boot(/*process.argv*/);
  })
  .catch(e => logger.log(e));

src/sample/sample.module.ts

import { Module } from '@nestjs/common';
import { SampleService } from './sample.service';
import { ConsoleModule } from 'nestjs-console';

@Module({
  imports: [ConsoleModule],
  providers: [SampleService],
})
export class SampleModule {}

src/sample/sample.service.ts

import { Injectable } from '@nestjs/common';
import { ConsoleService } from 'nestjs-console';

@Injectable()
export class SampleService {
  constructor(private readonly consoleService: ConsoleService) {
    // get the root cli
    const cli = this.consoleService.getCli();

    // e.g create a single command (See [npm commander for more details])
    cli.command('list <directory>')
      .description('List content of a directory')
      .action((directory: string) => {
        this.list(directory);
      });

    // e.g create a parent command container
    const parentCommand = this.consoleService.subCommands(
      cli,
      'new',
      'A command to create an item',
    );

    // e.g create sub command
    parentCommand
      .command('file <name>')
      .description('Create a file')
      .action((name: string) => {
        console.log(`Creating a file named ${name} at path`);
        process.exit(0);
      });

    // e.g why not an other one ?
    parentCommand
      .command('directory <name>')
      .description('Create a directory')
      .action((name: string) => {
        console.log(`Creating a directory named ${name}`);
        process.exit(0);
      });
  }

  list(directory: string): void | Promise<void> {
    // See Ora npm package for details about spinner
    const spin = this.consoleService.createSpinner();
    spin.start();
    console.log(`Listing files at path named ${directory}`);
    spin.stop();
    process.exit(0);
  }
}

Build output

$ npm run build
> [email protected] build ~/project/a-sample-project
> tsc -p tsconfig.build.json

node_modules/nestjs-console/lib/commander.d.ts:1:8 - error TS1192: Module '"~/project/a-sample-project/node_modulescommander/typings/index"' has no default export.

1 import commander from 'commander';
         ~~~~~~~~~

node_modules/nestjs-console/lib/service.d.ts:11:42 - error TS2503: Cannot find namespace 'ora'.

11     static createSpinner(text?: string): ora.Ora;
                                            ~~~

src/sample/sample.service.ts:11:9 - error TS2339: Property 'command' does not exist on type 'Command'.

11     cli.command('list <directory>')
           ~~~~~~~

src/sample/sample.service.ts:26:8 - error TS2339: Property 'command' does not exist on type 'Command'.

26       .command('file <name>')
          ~~~~~~~

src/sample/sample.service.ts:35:8 - error TS2339: Property 'command' does not exist on type 'Command'.

35       .command('directory <name>')
          ~~~~~~~

src/sample/sample.service.ts:45:38 - error TS2576: Property 'createSpinner' is a static member of type 'ConsoleService'

45     const spin = this.consoleService.createSpinner();
                                        ~~~~~~~~~~~~~


Found 6 errors.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc -p tsconfig.build.json`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2019-05-23T07_49_49_878Z-debug.log
$ npm run console:dev -- --help

> [email protected] console:dev ~/project/a-sample-project
> ts-node -r tsconfig-paths/register src/console.ts "--help"


~/project/a-sample-project/node_modules/ts-node/src/index.ts:240
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/sample/sample.service.ts:11:9 - error TS2339: Property 'command' does not exist on type 'Command'.

11     cli.command('list <directory>')
           ~~~~~~~
src/sample/sample.service.ts:26:8 - error TS2339: Property 'command' does not exist on type 'Command'.

26       .command('file <name>')
          ~~~~~~~
src/sample/sample.service.ts:35:8 - error TS2339: Property 'command' does not exist on type 'Command'.

35       .command('directory <name>')
          ~~~~~~~
src/sample/sample.service.ts:45:38 - error TS2576: Property 'createSpinner' is a static member of type 'ConsoleService'

45     const spin = this.consoleService.createSpinner();
                                        ~~~~~~~~~~~~~

    at createTSError (~/project/a-sample-project/node_modules/ts-node/src/index.ts:240:12)
    at reportTSError (~/project/a-sample-project/node_modules/ts-node/src/index.ts:244:19)
    at getOutput (~/project/a-sample-project/node_modules/ts-node/src/index.ts:360:34)
    at Object.compile (~/project/a-sample-project/node_modules/ts-node/src/index.ts:393:11)
    at Module.m._compile (~/project/a-sample-project/node_modules/ts-node/src/index.ts:439:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Object.require.extensions.(anonymous function) [as .ts] (~/project/a-sample-project/node_modules/ts-node/src/index.ts:442:12)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] console:dev: `ts-node -r tsconfig-paths/register src/console.ts "--help"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] console:dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     ~/.npm/_logs/2019-05-23T07_56_37_952Z-debug.log
$ npm run console -- --help

> [email protected] console ~/project/a-sample-project
> node dist/console.js "--help"

Usage: console [options] [command]

Options:
  -h, --help        output usage information

Commands:
  list <directory>  List content of a directory
  new               A command to create an item

from nestjs-console.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.