Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「captureRejections」 property not works in ts-node #1587

Closed
Scared-Heart opened this issue Dec 30, 2021 · 10 comments
Closed

「captureRejections」 property not works in ts-node #1587

Scared-Heart opened this issue Dec 30, 2021 · 10 comments

Comments

@Scared-Heart
Copy link

Search Terms

I wanna create a eventEmitter with 「captureRejections」
it works in with node.js
but not works with ts-node

Expected Behavior

create a eventEmitter instance with able to capture promise rejections with ts-node

Actual Behavior

「captureRejections」property not work with ts-node
but works with node

Steps to reproduce the problem

create a file testEvent.js

const { EventEmitter } = require('events');
const ee = new EventEmitter({ captureRejections: true });
console.log(ee)

run

ts-node testEvent.js

check console output

EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  [Symbol(kCapture)]: false
}

[Symbol(kCapture)]: false means 「captureRejections」property is not setted

however, when i use node

run

node testEvent.js

console output

EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  [Symbol(kCapture)]: true
}

[Symbol(kCapture)]: false means 「captureRejections」works

this is so confusing

Minimal reproduction

Specifications

  • ts-node version: v10.4.0

  • node version: v14.15.0

  • TypeScript version: 4.4.4

  • tsconfig.json, if you're using one: not use

  • Operating system and version: macos 10.15.5 (19F101)

@Scared-Heart
Copy link
Author

@cspotcode
Copy link
Collaborator

I'm unable to reproduce this. Usually when that happens, it means the reporter was making an honest mistake.

I've labelled this issue "needs more information" and I'll close in a few days if I don't hear back.

@Scared-Heart
Copy link
Author

I'm unable to reproduce this. Usually when that happens, it means the reporter was making an honest mistake.

I've labelled this issue "needs more information" and I'll close in a few days if I don't hear back.

const emitter = require('events')
const em1 = new emitter({ captureRejections: true })
console.log(em1)

I tried the code above on online runtime node.js again and it reproduced(node -v 14.x), 「captureRejections」property is setted with value true, the same result with my local test.
however, then i use local node.js REPL, it's different, 「captureRejections」property is false.
run with ts-node, 「captureRejections」is always setted with false.

So, first question is should ts-node works the same with node in 「experimental features」?
if that's true, i guess this is a problem need 2 be fixed cause it's a trap for dev.
second question is why node REPL works different with node $fileName.js ?
maybe i should create a issue for node?

@cspotcode
Copy link
Collaborator

Sounds like you've narrowed this down to a bug in the behavior of whatever version of node you have installed locally, is that right?

@Scared-Heart
Copy link
Author

Sounds like you've narrowed this down to a bug in the behavior of whatever version of node you have installed locally, is that right?

emm, it's just a clue when i saw your reply and tried again. Cause i guess, if you reproduced this code with node REPL then it's not right.

I tried with node version 12-17, it works fine with captureRejections property, but node REPL is wrong.

what i expected is that then i run this code with ts-node, it works the same as node, captureRejections can be applied to eventEmitter.

@cspotcode
Copy link
Collaborator

cspotcode commented Jan 4, 2022

I see, you are saying that the node REPL exhibits this bug? Then it is a node bug?

I modified your testEvent.js

// For some reason, the following import triggers this bug.
// If this import is removed, the bug goes away.
require('repl');

const { EventEmitter } = require('events');
const ee = new EventEmitter({ captureRejections: true });
console.log('Event emitter created with captureRejections: true, so `Symbol(kCapture) should be true');
console.log(ee);

And the bug reproduces on the latest node v17.3.0:

❯ node -v
v17.3.0

❯ node ./testEvent.js
Event emitter created with captureRejections: true, so `Symbol(kCapture) should be true
EventEmitter {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  [Symbol(kCapture)]: false
}

@Scared-Heart
Copy link
Author

exactly! I agree that it's a node bug. And i don't know how ts-node works different too, maybe caused by node.js 'repl' module.

@cspotcode
Copy link
Collaborator

When ts-node is loaded, it requires node's built-in 'repl' module. Importantly, this does not necessarily mean it creates a REPL.

ts-node/src/index.ts

Lines 29 to 34 in aff9bb9

export {
createRepl,
CreateReplOptions,
ReplService,
EvalAwarePartialHost,
} from './repl';

ts-node/src/repl.ts

Lines 4 to 9 in aff9bb9

import {
Recoverable,
ReplOptions,
REPLServer,
start as nodeReplStart,
} from 'repl';

This bug is triggered merely by require('repl'), which is why the bug occurs even when we are not using the REPL at all.

Because this is a node bug, I'm going to close this issue. Good luck!

@CMCDragonkai
Copy link

I can confirm this is a node bug as well. Has anybody created an issue upstream?

@CMCDragonkai
Copy link

Oh I found it nodejs/node#41391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants