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

Jest tests detect open handles for Node v20 (TTYWRAP) #2

Open
nktnet1 opened this issue Sep 7, 2024 · 3 comments
Open

Jest tests detect open handles for Node v20 (TTYWRAP) #2

nktnet1 opened this issue Sep 7, 2024 · 3 comments

Comments

@nktnet1
Copy link

nktnet1 commented Sep 7, 2024

For any Jest tests that uses

import esm from '@httptoolkit/esm';

e.g. running any tests in import-sync, the following error occurs in Node v20 (but not v18).

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  TTYWRAP

    > 1 | import esm from '@httptoolkit/esm';
        | ^
      2 |
      3 | import { Options } from './options';
      4 | import { findModuleFile, getCallerDirname } from './files';

      at Object.<anonymous> (node_modules/@httptoolkit/esm/esm.js:1:43442)
      at r (node_modules/@httptoolkit/esm/esm.js:1:603)
      at node_modules/@httptoolkit/esm/esm.js:1:795
      at node_modules/@httptoolkit/esm/esm.js:1:806
      at j (node_modules/@httptoolkit/esm/esm.js:1:1034)
      at Object.<anonymous> (node_modules/@httptoolkit/esm/esm.js:1:1692)
      at Object.<anonymous> (src/import.ts:1:1)
      at Object.<anonymous> (src/index.ts:1:1)
      at Object.<anonymous> (tests/resolver/resolver.test.ts:1:1)

@pimterry not sure if you have any idea?

@nktnet1
Copy link
Author

nktnet1 commented Sep 7, 2024

Not sure if related, but I also had some trouble installing dependencies for this project on Node 20 too (using npm i or npm ci).

Here's the error on node 20:

Node 20 Build Error Log
npm error code 1
npm error path /home/nktnet/programs/esm/node_modules/sleep
npm error command failed
npm error command sh -c node-gyp rebuild
npm error make: Entering directory '/home/nktnet/programs/esm/node_modules/sleep/build'
npm error   CXX(target) Release/obj.target/node_sleep/module_init.o
npm error make: Leaving directory '/home/nktnet/programs/esm/node_modules/sleep/build'
npm error gyp info it worked if it ends with ok
npm error gyp info using [email protected]
npm error gyp info using [email protected] | linux | x64
npm error gyp info find Python using Python version 3.12.5 found at "/usr/bin/python3"
npm error gyp info spawn /usr/bin/python3
npm error gyp info spawn args [
npm error gyp info spawn args '/home/nktnet/.local/share/fnm/node-versions/v20.15.1/installation/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm error gyp info spawn args 'binding.gyp',
npm error gyp info spawn args '-f',
npm error gyp info spawn args 'make',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/home/nktnet/programs/esm/node_modules/sleep/build/config.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/home/nktnet/.local/share/fnm/node-versions/v20.15.1/installation/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm error gyp info spawn args '-I',
npm error gyp info spawn args '/home/nktnet/.cache/node-gyp/20.15.1/include/node/common.gypi',
npm error gyp info spawn args '-Dlibrary=shared_library',
npm error gyp info spawn args '-Dvisibility=default',
npm error gyp info spawn args '-Dnode_root_dir=/home/nktnet/.cache/node-gyp/20.15.1',
npm error gyp info spawn args '-Dnode_gyp_dir=/home/nktnet/.local/share/fnm/node-versions/v20.15.1/installation/lib/node_modules/npm/node_modules/node-gyp',
npm error gyp info spawn args '-Dnode_lib_file=/home/nktnet/.cache/node-gyp/20.15.1/<(target_arch)/node.lib',
npm error gyp info spawn args '-Dmodule_root_dir=/home/nktnet/programs/esm/node_modules/sleep',
npm error gyp info spawn args '-Dnode_engine=v8',
npm error gyp info spawn args '--depth=.',
npm error gyp info spawn args '--no-parallel',
npm error gyp info spawn args '--generator-output',
npm error gyp info spawn args 'build',
npm error gyp info spawn args '-Goutput_dir=.'
npm error gyp info spawn args ]
npm error gyp info spawn make
npm error gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm error In file included from ../../nan/nan.h:176,
npm error                  from ../sleep.h:4,
npm error                  from ../module_init.cc:1:
npm error ../../nan/nan_callbacks.h:55:23: error: ‘AccessorSignature’ is not a member of ‘v8’
npm error    55 | typedef v8::Local<v8::AccessorSignature> Sig;
npm error       |                       ^~~~~~~~~~~~~~~~~
npm error ../../nan/nan_callbacks.h:55:40: error: template argument 1 is invalid
npm error    55 | typedef v8::Local<v8::AccessorSignature> Sig;
npm error       |                                        ^
npm error ../../nan/nan.h: In function ‘void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, GetterCallback, SetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, imp::Sig)’:
npm error ../../nan/nan.h:2542:19: error: no matching function for call to ‘v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>&, void (*&)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&), void (*&)(v8::Local<v8::Name>, v8::Local<v8::Value>, const v8::PropertyCallbackInfo<void>&), v8::Local<v8::Object>&, v8::AccessControl&, v8::PropertyAttribute&, Nan::imp::Sig&)’
npm error  2542 |   tpl->SetAccessor(
npm error       |   ~~~~~~~~~~~~~~~~^
npm error  2543 |       name
npm error       |       ~~~~         
npm error  2544 |     , getter_
npm error       |     ~~~~~~~~~      
npm error  2545 |     , setter_
npm error       |     ~~~~~~~~~      
npm error  2546 |     , obj
npm error       |     ~~~~~          
npm error  2547 |     , settings
npm error       |     ~~~~~~~~~~     
npm error  2548 |     , attribute
npm error       |     ~~~~~~~~~~~    
npm error  2549 |     , signature);
npm error       |     ~~~~~~~~~~~~   
npm error In file included from /home/nktnet/.cache/node-gyp/20.15.1/include/node/v8-function.h:15,
npm error                  from /home/nktnet/.cache/node-gyp/20.15.1/include/node/v8.h:33,
npm error                  from /home/nktnet/.cache/node-gyp/20.15.1/include/node/node.h:73,
npm error                  from ../../nan/nan.h:56:
npm error /home/nktnet/.cache/node-gyp/20.15.1/include/node/v8-template.h:809:8: note: candidate: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>, v8::AccessorGetterCallback, v8::AccessorSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, v8::SideEffectType, v8::SideEffectType)’
npm error   809 |   void SetAccessor(
npm error       |        ^~~~~~~~~~~
npm error /home/nktnet/.cache/node-gyp/20.15.1/include/node/v8-template.h:814:22: note:   no known conversion for argument 7 from ‘Nan::imp::Sig’ {aka ‘int’} to ‘v8::SideEffectType’
npm error   814 |       SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
npm error       |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm error /home/nktnet/.cache/node-gyp/20.15.1/include/node/v8-template.h:816:8: note: candidate: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::Name>, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, v8::SideEffectType, v8::SideEffectType)’
npm error   816 |   void SetAccessor(
npm error       |        ^~~~~~~~~~~
npm error /home/nktnet/.cache/node-gyp/20.15.1/include/node/v8-template.h:821:22: note:   no known conversion for argument 7 from ‘Nan::imp::Sig’ {aka ‘int’} to ‘v8::SideEffectType’
npm error   821 |       SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
npm error       |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm error ../module_init.cc: At global scope:
npm error /home/nktnet/.cache/node-gyp/20.15.1/include/node/node.h:1228:7: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
npm error  1228 |       (node::addon_register_func) (regfunc),                          \
npm error       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm error /home/nktnet/.cache/node-gyp/20.15.1/include/node/node.h:1262:3: note: in expansion of macro ‘NODE_MODULE_X’
npm error  1262 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
npm error       |   ^~~~~~~~~~~~~
npm error ../module_init.cc:24:1: note: in expansion of macro ‘NODE_MODULE’
npm error    24 | NODE_MODULE(node_sleep, init)
npm error       | ^~~~~~~~~~~
npm error make: *** [node_sleep.target.mk:111: Release/obj.target/node_sleep/module_init.o] Error 1
npm error gyp ERR! build error 
npm error gyp ERR! stack Error: make failed with exit code: 2
npm error gyp ERR! stack at ChildProcess.<anonymous> (/home/nktnet/.local/share/fnm/node-versions/v20.15.1/installation/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:209:23)
npm error gyp ERR! System Linux 6.10.6-arch1-1
npm error gyp ERR! command "/home/nktnet/.local/share/fnm/node-versions/v20.15.1/installation/bin/node" "/home/nktnet/.local/share/fnm/node-versions/v20.15.1/installation/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm error gyp ERR! cwd /home/nktnet/programs/esm/node_modules/sleep
npm error gyp ERR! node -v v20.15.1
npm error gyp ERR! node-gyp -v v10.1.0
npm error gyp ERR! not ok

Looks like the sleep/node-sleep module might be the cause. Could be worth updating it?

Downgrading to node 18, I can build successfully, but when attempting to publish locally with yalc

npx --yes yalc publish --private

I get the following error:

Node 18 Yalc Publish Error
(node:131762) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
(Use `node --trace-deprecation ...` to show where the warning was created)
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db

Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
node:internal/crypto/hash:69
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:69:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports (/home/nktnet/programs/esm/node_modules/webpack/lib/util/createHash.js:135:53)
    at NormalModule._initBuildHash (/home/nktnet/programs/esm/node_modules/webpack/lib/NormalModule.js:417:16)
    at handleParseError (/home/nktnet/programs/esm/node_modules/webpack/lib/NormalModule.js:471:10)
    at /home/nktnet/programs/esm/node_modules/webpack/lib/NormalModule.js:503:5
    at /home/nktnet/programs/esm/node_modules/webpack/lib/NormalModule.js:358:12
    at /home/nktnet/programs/esm/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/home/nktnet/programs/esm/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (/home/nktnet/programs/esm/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at /home/nktnet/programs/esm/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at context.callback (/home/nktnet/programs/esm/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /home/nktnet/programs/esm/node_modules/babel-loader/lib/index.js:59:71 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v18.20.4
Error: Command failed with exit code 1: webpack --display-optimization-bailout
    at makeError (/home/nktnet/programs/esm/node_modules/execa/lib/error.js:59:11)
    at handlePromise (/home/nktnet/programs/esm/node_modules/execa/index.js:114:26)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  shortMessage: 'Command failed with exit code 1: webpack --display-optimization-bailout',
  command: 'webpack --display-optimization-bailout',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

Downgrading once more to node 16 and everything works. As an aside, I'm switch node versions using fnm.

@pimterry
Copy link
Member

pimterry commented Sep 9, 2024

No idea about the Jest issue.

From the other points, it looks like:

  • This project depends on a native module sleep, which doesn't compile in Node 20+
  • This project is still using webpack v4, which uses some legacy OpenSSL features that aren't supported in Node v18+ (you can work around this with the --openssl-legacy-provider Node option). That's the cause of the digital envelope routines::unsupported error.

To be honest, I'm not sure how much time it's worth investing here. For older nodes this is useful, but for new Node releases (the latest releases of v20, v22, and any future versions) synchronous ESM require is now supported anyway.

In both the cases above, it's going to take a fair bit of work to update this and I'm not likely to have any time for that myself in the short term at least. What do you think?

@nktnet1
Copy link
Author

nktnet1 commented Sep 9, 2024

Fully agree - or rather, I think we should push people to use the new features if they're available for node v20+ instead of providing support for them here.

Just wanted to raise the issue - thanks @pimterry!

Feel free to close :).

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

No branches or pull requests

2 participants