maxlath / wikibase-cli

read and edit a Wikibase instance from the command line
MIT License
227 stars 24 forks source link

TypeError: Cannot destructure property writeFile #110

Closed daniel-barrows closed 4 years ago

daniel-barrows commented 4 years ago

I just installed wikidata on Ubuntu 18.04.3 LTS via npm. I can't get past the configuration step. wd help outputs fine, but wd config returns errors. See more below.

$ lsb_release -d
Description:    Ubuntu 18.04.3 LTS
$ nodejs --version
v8.10.0
$ npm --version
3.5.2
$ wd --version
12.0.0
$ wd config path
/usr/local/lib/node_modules/wikibase-cli/lib/config/file_operations.js:1
(function (exports, require, module, __filename, __dirname) { const { writeFile } = require('fs').promises
                                                                      ^

TypeError: Cannot destructure property `writeFile` of 'undefined' or 'null'.
    at Object.<anonymous> (/usr/local/lib/node_modules/wikibase-cli/lib/config/file_operations.js:1:98)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/lib/node_modules/wikibase-cli/bin/wb-config:5:17)
    at Module._compile (module.js:652:30)
$ wd id 'Wikidata'
FetchError: request to https://c.wikipedia.org/w/api.php?format=json&action=query&redirects&titles=Wikidata failed, reason: getaddrinfo ENOTFOUND c.wikipedia.org c.wikipedia.org:443
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/wikibase-cli/node_modules/node-fetch/lib/index.js:1455:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
Context: undefined

Similar errors are output for all commands of wd config. I'm guessing the error of wd id is related to the locale not being configured, so it assumes 'c'.

maxlath commented 4 years ago

the issue was that require('fs').promises only exists for NodeJS >= v10, I reverted to using require('fs').writeFileSync instead to recover support for NodeJS v8, but note that as v8 has now passed End-of-Life date, the support might be dropped in future releases