huggingface / node-question-answering

Fast and production-ready question answering in Node.js
Apache License 2.0
464 stars 55 forks source link

SyntaxError: await is only valid in async function #9

Closed alikabeer32 closed 4 years ago

alikabeer32 commented 4 years ago

my code:

const { QAClient } = require("question-answering"); // If using vanilla JS

const text = `
  Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season.
  The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.
  As this was the 50th Super Bowl, the league emphasized the "golden anniversary" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as "Super Bowl L"), so that the logo could prominently feature the Arabic numerals 50.
`;

const question = "Who won the Super Bowl?";

const qaClient = await QAClient.fromOptions();
const answer = await qaClient.predict(question, text);

console.log(answer); // { text: 'Denver Broncos', score: 0.3 }

Error :

SyntaxError: await is only valid in async function at wrapSafe (internal/modules/cjs/loader.js:1063:16) at Module._compile (internal/modules/cjs/loader.js:1111:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10) at Module.load (internal/modules/cjs/loader.js:996:32) at Function.Module._load (internal/modules/cjs/loader.js:896:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47

alikabeer32 commented 4 years ago

Update: I put it in an async function but now I get this error: Error: The specified module could not be found. \?\C:\project\node_modules\question-answering\node_modules\@tensorflow\tfjs-node\lib\napi-v5\tfjs_binding.node

Pierrci commented 4 years ago

It seems your problem is related to the underlying TensorFlow library. Can you try running npm i @tensorflow/tfjs-node in your project to be sure it's correctly installed and try again?

braaannigan commented 4 years ago

I get the same issue as @alikabeer32

I've run the npm i above and have the following package.json

    "@tensorflow/tfjs-node": "^1.7.4",
    "question-answering": "^2.0.1"

Any sugggestions?

braaannigan commented 4 years ago

I'm on node version v10.13.0 btw

Pierrci commented 4 years ago

Which issue are you referring to exaclty @braaannigan? The one from the first message or the second message?

braaannigan commented 4 years ago

Hi @Pierrci I think I fixed this by updating all my versions of node/npm etc. Have had a computer rebuild in the interim, so can't provide any more detail unfortunately.

Pierrci commented 4 years ago

Great! Closing this for now, feel free to reopen if needed.