kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
50 stars 6 forks source link

throws "API_URL.includes" is not a function when creating wikiapi instance #58

Closed summerset-zz closed 2 years ago

summerset-zz commented 2 years ago

Hey: I'm trying to build a little template-to-csv tool with wikiapi. the problem in the title occurs when the script runs new Wikiapi("https://warframe.huijiwiki.com/api.php")

the environment I use as below:

the full code I ran as below:

const Wikiapi = require('wikiapi')
(async() => {
    const wiki = new Wikiapi('https://warframe.huijiwiki.com/api.php')
    let pageData = await wiki.page('吞天沙暴', {})
    console.log(pageData)
})()

the error in the console:

D:\git repo\warframe-items-for-huiji\node_modules\cejs\application\net\wiki.js:201
            API_URL.includes('://')) {
                    ^

    at new wiki_API (D:\git repo\warframe-items-for-huiji\node_modules\cejs\application\net\wiki.js:201:21)
    at Wikiapi (D:\git repo\warframe-items-for-huiji\node_modules\wikiapi\Wikiapi.js:92:23)
    at Object.<anonymous> (D:\git repo\warframe-items-for-huiji\scripts\parseTemplateData.js:6:1)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155: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

I tried a little debug on the module and located the problem:

yet I'm too noob to fix it, I need advice, thank you~

kanasimi commented 2 years ago

I think this is a problem due to an older version. I have just released cejs 4.5.2, please try the new version and report back if it works, thanks.

summerset-zz commented 2 years ago

I think this is a problem due to an older version. I have just released cejs 4.5.2, please try the new version and report back if it works, thanks.

Still not working:

D:\git repo\warframe-items-for-huiji\node_modules\cejs\application\net\wiki.js:198
                && API_URL.includes('://')) {
                           ^

TypeError: API_URL.includes is not a function
    at new wiki_API (D:\git repo\warframe-items-for-huiji\node_modules\cejs\application\net\wiki.js:198:14)
    at Wikiapi (D:\git repo\warframe-items-for-huiji\node_modules\wikiapi\Wikiapi.js:92:23)
    at Object.<anonymous> (D:\git repo\warframe-items-for-huiji\scripts\parseTemplateData.js:5:5)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155: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

package-lock.json:

"cejs": {
            "version": "4.5.2",
            "resolved": "https://registry.npmmirror.com/cejs/-/cejs-4.5.2.tgz",
            "integrity": "sha512-GfDi1OVIkkYEOPEEBEcwkKVQ2vxSSxsbT7B7VrvNp7QRMiccGgaQtT/OkiK0yB06sZhFvr9tDVRc5n2JQwmawQ=="
        }
kanasimi commented 2 years ago

I am a bit curious because new Wikiapi('https://warframe.huijiwiki.com/api.php') is passing in a string, and wiki_API should also only receive the string. I tried it on my machine and I can get [[吞天沙暴]] properly. Maybe you can provide some code for parseTemplateData.js for me to try?

summerset-zz commented 2 years ago

--solved--

Well I tried another method and it worked.

I removed the 'async domain', and instead wrapped it in an async function, and run it after definition and it worked(at least the server responsed)

the code as below:

const WikiApi = require('wikiapi')

async function main() {
    const wiki = new WikiApi('https://sands-of-salzaar.fandom.com/api.php')
    let pageData = await wiki.page('Classes', {})
    debugger
}

main()

so I'm just curious why (async()=>{/*codes here*/})() not working.

anyway thanks alot~

kanasimi commented 2 years ago

@summerset-zz I am very interested in your report. In fact I myself use (async()=>{/*codes here*/})() https://github.com/kanasimi/wikibot/blob/master/routine/20211203.synchronizing_common_pages.js#L57 And I have no problem running with your example. If you don't mind, can you provide the code to reproduce the problem independently? Thank you.