Comments (9)
I tried by syncing the node version. No luck, no bug.
By stepping through the call stack, I notice the error is due to the this.listeners array does not contain the schema:sync command in node_modules/commander/index.js:891. It then throws an error which goes to the catch block in console.ts and the process rightfully exits.
The this.listeners can not contain the schema:sync
command. This command is not registered on commander and had nothing to do with it. Only the entry point cli.js (from typeorm) can understand schema:sync
command.
Note that the nestjs-console module is not doing anything to your app instance outside the context of the bootstrap console.ts/js file.
Does nestjs-console check/lift/sync yargs based commands as well? It seems to hijack the entrypoint for all commands and not only Commander based commands.
I searched and it seems commander is not using yargs.
nestjs-console is not invoked when you call the typeorm command. It is initialized and working only if you use the console.ts/js file as entry point. The init and boot are done in this file only.
So the first thing to check is WHY the stack contains code from the nestjs-console module when you call the cli of typeorm.
Is really the nestjs-console module that is throwing the error ? If yes, why ? It shouldn't be in the stack.
it's a different context, like a different application.
Maybe you can try to investigate here, this is the only place where the console module is throwing a command not found
error.
Lines 226 to 230 in ff2d4a3
Maybe you have a global node module that is interacting on your computer ?
Could you try on a fresh node install ?
thx.
from nestjs-console.
Be sure to have commander 4.1.1 and not v5.0.0
Commander has published a new major version and the console module is not yet ready for it.
from nestjs-console.
This was indeed the case! tyvm
from nestjs-console.
I may have been a bit fast, turns out I was standing in a branch where the console was not added. This behaviour is observed on [email protected] as well.
I have setup a repo here:
https://github.com/MichaelHindley/nestjs-console-repro
Run npm i && npm build
to setup.
Then, running npm run typeorm schema:sync
results in:
"schema:sync" command not found
removing the ConsoleModule
from app.module.ts
fixes it.
from nestjs-console.
Thanks for the repo, let me have a look and come back to you.
from nestjs-console.
After clone, i had to add the import of the ConsoleModule in the AppModule.
It was not present.
Then i ran the command to be sure the console was working
ts-node -r tsconfig-paths/register src/console.ts "--help"
As expected the result was
Usage: console.ts [options] [command]
Options:
-h, --help output usage information
Commands:
list <directory> List content of a directory
Then i ran the typeorm command you gave me (after installing and starting a postgres sql server)
I had to remove the debugger flag (--inspect-brk) cause i do not have a debugger ready.
npm run typeorm schema:sync
The result was
query: START TRANSACTION
query: SELECT * FROM "information_schema"."tables" WHERE "table_schema" = current_schema() AND "table_name" = 'typeorm_metadata'
query: COMMIT
Schema syncronization finished successfully.
Everything worked well.
I am sorry, I was not able to reproduce the bug.
from nestjs-console.
(I pushed the changes missing in the repro)
Super interesting, my output for ts-node -r tsconfig-paths/register src/console.ts "--help"
is the same as yours, but here is my output for npm run typeorm schema:sync
Removing ConsoleModule gives me the same output for npm run typeorm schema:sync
as you.
By stepping through the call stack, I notice the error is due to the this.listeners
array does not contain the schema:sync
command in node_modules/commander/index.js:891
. It then throws an error which goes to the catch block in console.ts and the process rightfully exits.
If I remove the ConsoleModule, the commander breakpoints are not even hit, this is because typeorm uses the yargs
package for defining commands and not Commander.
If I remove the process.exit(1)
line, I still get the error from Commander that the command is not found, but then it goes to yargs
and runs the command successfully, since it does exist in that context.
Does nestjs-console check/lift/sync yargs
based commands as well? It seems to hijack the entrypoint for all commands and not only Commander based commands.
I do wonder how come in your case, the error is not thrown, since the code path would result in an empty this.listeners
in Commander no matter how I look at it, and thus throw an error which would lead to the process.exit(1)
block every time. Could you perhaps print the members of your this.listeners
array out?
node: 12.9.1
os: MacOS Catalina 0.15.4
from nestjs-console.
I can confirm that the code in console.ts
was executed because of typeORM doing a require
call to all files matching the glob for entities
in ormconfig.json
, in this particular case it was adding all .js
files in the dist
directory, where console.js
was as a result of npm run build
.
The require call was then executing the inline bootstrap code.
So that was the root cause! :)
from nestjs-console.
Nice catch ! I was testing using sources, this is why the bug was not present. The dist folder is not existing on my side.
from nestjs-console.
Related Issues (20)
- Update commander peerdependencies version HOT 2
- Examples doesn't work? HOT 2
- Documentation update for using opts HOT 5
- Support in nest v8 HOT 3
- _actionResults is undefined HOT 1
- Unable to add a global option HOT 2
- Unable to register commands in nestjs-console HOT 4
- CLI will _always_ throw an error even with empty promise handler HOT 3
- Can't read CLI options to configure the database HOT 3
- TypeError: parent.addCommand is not a function HOT 5
- Task Not Exiting HOT 2
- Support nestjs@9 HOT 2
- use enableShutdownHooks with nest-console
- ERROR [ExceptionHandler] undefined HOT 1
- Process.env issue HOT 3
- How to pass array of strings? HOT 1
- Example is slow? HOT 2
- Support for NestJs v10 HOT 2
- Module '"nestjs-console"' has no exported member 'createSpinner'. HOT 5
- What does this project do differently compared to nest-commander ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs-console.