ezra-bible-app / node-sword-interface

JavaScript (N-API) interface to SWORD library
GNU General Public License v2.0
22 stars 2 forks source link

Install KJV example not working #23

Closed nikitazdvijkov closed 3 years ago

nikitazdvijkov commented 3 years ago

Steps:

  1. Install dependencies for Mac using instructions in README.
  2. Clone and npm install the repo.
  3. Run node examples/install_kjv.js.

Result:

Detected old InstallMgr directory installMgr.
Updating repository configuration ...
Installing King James module
/Users/asdf/dev/node-sword-interface/index.js:240
      this.nativeInterface.installModule(moduleCode, progressCB, function(result) {
                           ^

TypeError: String expected for argument 1
    at /Users/asdf/dev/node-sword-interface/index.js:240:28
    at new Promise (<anonymous>)
    at NodeSwordInterface.installModule (/Users/asdf/dev/node-sword-interface/index.js:239:12)
    at installKJV (/Users/asdf/dev/node-sword-interface/examples/install_kjv.js:30:19)
nikitazdvijkov commented 3 years ago

I get the same error when I attempt to create a new project, as opposed to cloning this repo.

Steps:

npm init -y
npm install node-sword-interface

Copy the example from the README into install_kjv.js:

const NodeSwordInterface = require('node-sword-interface');
var interface = new NodeSwordInterface();

async function installKJV() {
  console.log("Updating repository configuration ...");
  await interface.updateRepositoryConfig();

  console.log("Installing King James module");
  // Install the King James Version (Uses the internet connection to download and install the module)
  await interface.installModule('KJV');
}

installKJV().then(() => {
  console.log("Installation of KJV successfully completed!");
});

Run via node install_kjv.js.

nikitazdvijkov commented 3 years ago

Node v16.5.0

NPM v7.21.0

tobias-klein commented 3 years ago

Thank you so much @nikitazdvijkov for reporting this! Something has changed in the API since the example has been created. This will certainly be fixed in the next version.

The first parameter of installModule is the progress callback function. If you adjust the respective call in the example, it should work:

await interface.installModule(undefined, 'KJV');

I can see how the new API is a bit inconvenient. I had a reason to change the API end of last year, but I can check whether this is still valid as of today.

nikitazdvijkov commented 3 years ago

That fixed it, thanks!

tobias-klein commented 3 years ago

I fixed the API with 764237d1998734e53aea4ea7740d37e805c6911b and version 0.236.0 (published on npmjs). The examples are now working again without any changes.

kthenrique commented 3 years ago

Hi I'm trying to run this same example. I've used npm to install the module. The unmodified example gives me:

Updating repository configuration ... Installing King James module node:internal/process/promises:246 triggerUncaughtException(err, true / fromPromise /); ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function wit hout a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejec ted with the reason "-9".] { code: 'ERR_UNHANDLED_REJECTION' }

Using

await interface.installModule(undefined, 'KJV');

gives me:

Updating repository configuration ... Installing King James module node_modules/node-sword-interface/index.js:240 this.nativeInterface.installModule(moduleCode, progressCB, function(result) { ^

TypeError: String expected for argument 1 at node_modules/node-sword-interface/index.js:240:2 8 at new Promise () at NodeSwordInterface.installModule (node_modules/n ode-sword-interface/index.js:239:12) at installKJV (install_kjv.js:13:19)

Cloning master works tho!

Node v16.11.0 Npm v7.24.1

tobias-klein commented 3 years ago

Thanks for checking this once more. Maybe something went wrong when publishing the package. I am going to re-open this issue and re-publish the package with a new version.

tobias-klein commented 3 years ago

Mmmm... @kthenrique Which exact example code did you use?

If I install the latest version 0.236.0 via npm I can run the included example without any issues like this (first cd into the directory of node-sword-interface):

node examples/install_kjv.js

The adjustment above is no longer necessary, which means that await interface.installModule('KJV'); as shown in the latest README should work.

kthenrique commented 3 years ago

Oh this is odd! Now it works... I've no clue what is different now! sorry for the inconvenience.