sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 25 forks source link

UnhandledPromiseRejectionWarning: TypeError: ssh2_promise_1.default is not a constructor #68

Closed kulame closed 2 years ago

kulame commented 3 years ago

mycode

import SSH2Promise from 'ssh2-promise';

export const fetch = async () => {
  const config = {
  };
  console.log(SSH2Promise);
  const ssh = new SSH2Promise(config);
  ssh.connect().then(() => {
    console.log('connected');
  });
};
await fetch()

it's report a error.

➜  tok git:(master) ✗ npx ts-node bin/load.ts
download ...
undefined
(node:5509) UnhandledPromiseRejectionWarning: TypeError: ssh2_promise_1.default is not a constructor
    at fetch (/srv/project/tok/bin/bot.ts:13:15)
    at task (/srv/project/tok/bin/load.ts:101:14)
    at /srv/project/tok/bin/load.ts:119:11
    at Array.map (<anonymous>)
    at /srv/project/tok/bin/load.ts:118:23
    at Object.<anonymous> (/srv/project/tok/bin/load.ts:122:3)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Module.m._compile (/srv/project/tok/node_modules/ts-node/src/index.ts:1365:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object.require.extensions.<computed> [as .ts] (/srv/project/tok/node_modules/ts-node/src/index.ts:1368:12)
rootowsky commented 2 years ago

I was ablet o fix this by replacing an import with require: import SSH2Promise = require('ssh2-promise');

sanketbajoria commented 2 years ago

@kulame @rootowsky this section tell how we can use it

https://github.com/sanketbajoria/ssh2-promise#require