yuko1101 / enka-network-api

A Node.js Enka.Network API wrapper for Genshin Impact.
https://enka-network-api.vercel.app
MIT License
96 stars 7 forks source link

"SyntaxError: Unexpected token _ in JSON at position 0" error. #40

Closed mendoitarou closed 1 year ago

mendoitarou commented 1 year ago

My system environment

OS => Debian GNU/Linux 11 (bullseye) Node.js => v18.16.0 npm => 9.5.1 enka-network-api => 3.2.0

What happened?

When the sample was run, the following error occurred

(JSON Data)

SyntaxError: Unexpected token _ in JSON at position 0
    at JSON.parse (<anonymous>)
    at CachedAssetsManager.getGenshinCacheData (/home/~~~/test/node_modules/enka-network-api/dist/client/CachedAssetsManager.js:318:69)
    at EnkaClient.getAllWeapons (/home/~~~/test/node_modules/enka-network-api/dist/client/EnkaClient.js:242:50)
    at Object.<anonymous> (/home/~~~/test/weapon.js:4:22)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.16.0

Am I doing something wrong? Thank you.

yuko1101 commented 1 year ago

Thank you for your issue.

It seems that there is something wrong with unzipper which enka-network-api uses. I released version 3.2.2 and got rid of unzipper.

Please update enka-network-api by running npm i enka-network-api@latest

yuko1101 commented 1 year ago

If you moved the cache directory, you need to update contents with CachedAssetsManager#fetchAllContents.

mendoitarou commented 1 year ago

Thanks! Thanks to you, I no longer get the above error!

However, when I run the following code's, I am getting another error.

const { EnkaClient } = require("enka-network-api");
const enka = new EnkaClient({ showFetchCacheLog: true, cacheDirectory: "./cache",defaultLanguage: "jp"});
enka.cachedAssetsManager.cacheDirectorySetup();
enka.cachedAssetsManager.fetchAllContents();

function weapon_icon_url_get() {
    const weapons = enka.getAllWeapons();
    weapons.map(async w => {
        var name = w.name.get();
        var pic_url = w.awakenIcon.url;
        console.log(`${name} : ${pic_url}\n`);
    });
}

weapon_icon_url_get()

ERROR_LOG

(WeaponName : WeaponIconURL)
狩人の道 : https://enka.network/ui/UI_EquipIcon_Bow_Ayus_Awaken.png
(Example)

Downloading cache.zip...
node:internal/fs/utils:347
    throw err;
    ^

Error: ENOENT: no such file or directory, lstat '/home/~~~/test/node_modules/enka-network-api/cache-downloaded.zip'
    at Object.lstatSync (node:fs:1593:3)
    at __node_internal_ (node:internal/fs/utils:821:8)
    at Object.rmSync (node:fs:1273:13)
    at /home/~~~/test/node_modules/enka-network-api/dist/client/CachedAssetsManager.js:476:38
    at /home/~~~/test/node_modules/adm-zip/adm-zip.js:705:33
    at /home/~~~/test/node_modules/adm-zip/util/utils.js:103:41
    at suppressedCallback (node:fs:273:5)
    at FSReqCallback.oncomplete (node:fs:198:23) {
  errno: -2,
  syscall: 'lstat',
  code: 'ENOENT',
  path: '/home/~~~/test/node_modules/enka-network-api/cache-downloaded.zip'
}

Node.js v18.16.0

Am I doing something wrong? If you don't mind, I would appreciate it if you could tell me what I am doing wrong.

yuko1101 commented 1 year ago

Thank you for reporting.

It's a problem with enka-network-api. I'll fix it in the next version. (Will be v3.2.3)

mendoitarou commented 1 year ago

Thanks for the quick response! Looking forward to seeing the improvements in the update!

yuko1101 commented 1 year ago

I released the patch v3.2.3. Please update the package with npm i enka-network-api@latest

mendoitarou commented 1 year ago

It worked out fine! Thank you! (issueのクローズは私がするべきですか?)

yuko1101 commented 1 year ago

こちらで閉じておきます