Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new to javascript, can't get anything to work #19

Open
henrydatei opened this issue Apr 25, 2022 · 3 comments
Open

new to javascript, can't get anything to work #19

henrydatei opened this issue Apr 25, 2022 · 3 comments

Comments

@henrydatei
Copy link

Hi, I'm totally new to javascript and I can't get this to run. I made a new folder and run inside this

npm init
npm i wikifolio

I created a new file index.js with this content

import Api from 'wikifolio'

const api = new Api({
  email: 'my email',
  password: 'my password'
})

const wikifolio = api.wikifolio('wf000igb03')
console.log( await wikifolio.details() )
console.log( await wikifolio.price() )

But I get the following error when running node index:

(node:6987) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/henryhaustein/Downloads/wikifolio/index.js:1
import Api from 'wikifolio'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1032:15)
    at Module._compile (node:internal/modules/cjs/loader:1067:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

When I add "type": "module" to the package.json file I get the following error

file:///Users/henryhaustein/Downloads/wikifolio/index.js:3
const api = new Api({
            ^

TypeError: Api is not a constructor
    at file:///Users/henryhaustein/Downloads/wikifolio/index.js:3:13
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)
@jekru
Copy link
Contributor

jekru commented Apr 25, 2022

I would recommend to use TypeScript.

npm init -y
npx tsc --init
npm install wikifolio
mkdir example.ts
import { Api } from 'wikifolio';


async function fetchPrice() {
    const api = new Api({email: '', password: ''});
    const wikifolio = api.wikifolio('')
    
    const price = await wikifolio.price();
    console.log(price);
}

fetchPrice();
npx ts-node example.ts

@henrydatei
Copy link
Author

henrydatei commented Apr 25, 2022

Thank you very much for your fast and working answer, but when I use instead of .price() the .details() method, I get another error :(

import { Api } from 'wikifolio';

async function main() {
    const api = new Api({email: 'email', password: 'password'});
    const wikifolio = api.wikifolio('wikifolioID')
    
    //const price = await wikifolio.price();
    //console.log(price);
    const details = await wikifolio.details();
    console.log(details);
}

main();
/Users/henryhaustein/Downloads/wikifolio/node_modules/wikifolio/src/models/Wikifolio.ts:411
      throw new Error('Wikifolio JSON not found. This is probably a bug, please report it.')
            ^
Error: Wikifolio JSON not found. This is probably a bug, please report it.
    at Wikifolio.<anonymous> (/Users/henryhaustein/Downloads/wikifolio/node_modules/wikifolio/src/models/Wikifolio.ts:411:13)
    at step (/Users/henryhaustein/Downloads/wikifolio/node_modules/wikifolio/dist/models/Wikifolio.js:44:23)
    at Object.next (/Users/henryhaustein/Downloads/wikifolio/node_modules/wikifolio/dist/models/Wikifolio.js:25:53)
    at fulfilled (/Users/henryhaustein/Downloads/wikifolio/node_modules/wikifolio/dist/models/Wikifolio.js:16:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

@jekru
Copy link
Contributor

jekru commented Apr 25, 2022

Thank you very much for your fast and working answer, but when I use instead of .price() the .details() method, I get another error :(

throw new Error('Wikifolio JSON not found. This is probably a bug, please report it.')

See #15. Wikifolio recently released a new version, that's why some features are currently broken. I hope to find some time to fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants