ssh2-sftp-client: Node 23: sftp.get() gives error "isDate is not a function"
As said in the title, when using the packing in node v23.5.0, the following snipped throws the “isDate is not a function” error
await sftp.connect(-your connection credentials-) const data = await sftp.get(-your path-)
Thanks for looking into this, looking forward to further releases.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 20 (10 by maintainers)
Not wrong, at least not completely. While npm update won’t pull the new version a reinstall of ssh2-sftp-client and fresh installs of ssh2-sftp-client will pull ssh2 v1.16.0. Removal of node_modules and package-lock.json followed by an npm i will therefore pull in ssh2 v1.16.0. All you need to do to update your project to use ssh2 1.16.0 is a reinstall of ssh2-sftp-client. See below transcript from fresh install of ssh2-sftp-client (I have edited it to remove my prompt escape sequences to make it print better)
Script started on 2025-01-30 08:50:02+11:00 [TERM=“tmux-256color” TTY=“/dev/pts/3” COLUMNS=“149” LINES=“29”] @.***~/tmp$ npm init -y Wrote to /home/tim/tmp/package.json:
{ “name”: “tmp”, “version”: “1.0.0”, “main”: “index.js”, “scripts”: { “test”: “echo "Error: no test specified" && exit 1” }, “keywords”: [], “author”: “”, “license”: “ISC”, “description”: “” }
@.***:~/tmp$ npm i ssh2-sftp-client added 20 packages, and audited 21 packages in 4s
2 packages are looking for funding run
npm fundfor detailsfound 0 vulnerabilities @.:~/tmp$ cat package.json { “name”: “tmp”, “version”: “1.0.0”, “main”: “index.js”, “scripts”: { “test”: “echo "Error: no test specified" && exit 1” }, “keywords”: [], “author”: “”, “license”: “ISC”, “description”: “”, “dependencies”: { “ssh2-sftp-client”: “^11.0.0” } } @.:~/tmp$ cat node_modules/ssh2/package.json { “name”: “ssh2”, “version”: “1.16.0”, “author”: “Brian White @.>", “description”: “SSH2 client and server modules written in pure JavaScript for node.js”, “main”: “./lib/index.js”, “engines”: { “node”: “>=10.16.0” }, “dependencies”: { “asn1”: “^0.2.6”, “bcrypt-pbkdf”: “^1.0.2” }, “devDependencies”: { @./eslint-config”: “^1.1.0”, “eslint”: “^7.32.0” }, “optionalDependencies”: { “cpu-features”: “~0.0.10”, “nan”: “^2.20.0” }, “scripts”: { “install”: “node install.js”, “rebuild”: “node install.js”, “test”: “node test/test.js”, “lint”: “eslint --cache --report-unused-disable-directives --ext=.js .eslintrc.js examples lib test”, “lint:fix”: “npm run lint – --fix” }, “keywords”: [ “ssh”, “ssh2”, “sftp”, “secure”, “shell”, “exec”, “remote”, “client” ], “licenses”: [ { “type”: “MIT”, “url”: “http://github.com/mscdex/ssh2/raw/master/LICENSE” } ], “repository”: { “type”: “git”, “url”: “http://github.com/mscdex/ssh2.git” } } @.***:~/tmp$ Script done on 2025-01-30 08:52:26+11:00 [COMMAND_EXIT_CODE=“0”]
So the choice is, fork the repo, change the ssh2 entry, publish your fork and use it. At some later point, when a new version of ssh2-sftp-client is pushed out, either update and republish your fork or switch back to the original version and update your project and push out a new version of that or…
rm -rf node_modules rm package-lock.json npm i
Choice up to you.
Should note that a new version of ssh2-sftp-client will be pushed out in the next few weeks once I have time to fix up a couple of other minor issues and finish investigating a different issue which may or may not involve more significant code changes.
wrong. Since 1.15 is satisfied, npm isn’t trying to pull a most recent one, it will pull 1.15. The only way to force npm to use 1.16 is to add a dummy ssh2 entry in the package.json with version 1.16. Then, and only then, npm will use 1.16 in place of 1.15 because 1.16 satisfies
^1.15.Tried and tested with npm version 11.0.0
A fork is completely unnecessary. All you need to do is run npm update or remove BOTH node_modules and package.lock and then run npm i, but if you wsant to fork and manage your own version, go for it.
With the versioning system, compatible means install the latest version which satisfies the version spec. In this case, latest version is 1.16.0, unless your using an npmjs mirror which has not been updated to the latest version and which has only version 1.15.0. However, as 1.16.0 has been out for some time, this is very unlikely.
Sounds like there is something wrong with your node/npm environment.
I have verified that removing node_modules and runninmg npm i installs 1.16.0. Likewise I have verified that with an install that already has 1.15.0, running npm outdated shows that the current version is 1.15.0 and the wanted version is 1.16.0. Then running npm update results in ssh2 being updated to 1.16.0
If this is not how it is working in your environment, then there is a problem with your npm as this is precisely how the npm versioning system is supposed to work and the point of the ^ specifier.
what does npm outdated show?
You might get more insight by running ‘npm doctor’. Perhaps also check you haven’t got something set in your .npmrc file which is changing the default behaviour.
Note that if you deleted node_modules and ran npm i but did not also delete package.lock, then you will not have got the updates as the package.lock will override the default behaviour. This is partly why best practice recommends never putting package.lock into your git repository as it wil prevent packages from being updated when you do npm i. The point of package.lock is to keep packages at a specific version so that you can install in multiple places and know you will have the same versions regardless of any updates published to npmjs or other package repositories. Running npm update will override and update package.lock.
I should also mention that I have observed for the last few node versions that it is important to re-install all the dependencies following any change to the node version. I use ‘n’ to manage node versions and have observed that after changing to a different node version there is a HUGE degradation of performance when running tests i.e. running the tests will take between 5 and 10 MINUTES when normally the tests take less than 1 minutes to run. Deleting node_modules and re-running npm install fixes this issue. Bottom line, makie sure you delete node_modules and then run npm install after changing node versions.