AtoraSuunva / booru

Searches boorus for images using some js magic
https://www.npmjs.com/package/booru
MIT License
78 stars 19 forks source link

Linux error #80

Closed azurenekowo closed 2 years ago

azurenekowo commented 2 years ago

When I run this module on a Linux device it just crashes with this error code:


/home/pi/scraperv212/node_modules/booru/dist/Utils.js:1
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.compareArrays=exports.validateSearchParams=exports.randInt=exports.shuffle=exports.jsonfy=exports.resolveSite=void 0;const Constants_1=require("./Constants"),fast_xml_parser_1=require("fast-xml-parser");function resolveSite(t){if("string"!=typeof t)return null;t=t.toLowerCase();for(const r in Constants_1.sites)if(r===t||Constants_1.sites[r].domain===t||Constants_1.sites[r].aliases.includes(t))return r;return null}function jsonfy(t){if("object"==typeof t)return t;const r=(0,fast_xml_parser_1.parse)(t,{ignoreAttributes:!1,attributeNamePrefix:""});if(r.html||r["!doctype"]){const t=r.html||r["!doctype"]?.html,e=[];throw t.body.h1&&e.push(t.body.h1),t.body.p&&e.push(t.body.p["#text"]),new Constants_1.BooruError(`The Booru sent back an error: '${e.join(": ")}'`)}return r.posts.post?r.posts.post:r.posts.tag?Array.isArray(r.posts.tag)?r.posts.tag:[r.posts.tag]:[]}function shuffle(t){let r,e,o=t.length;for(;0!==o;)e=Math.floor(Math.random()*o),o-=1,r=t[o],t[o]=t[e],t[e]=r;return t}function randInt(t,r){return t=Math.ceil(t),r=Math.floor(r),Math.floor(Math.random()*(r-t+1))+t}function validateSearchParams(t,r){const e=resolveSite(t);if("number"!=typeof r&&(r=parseInt(r,10)),null===e)throw new Constants_1.BooruError("Site not supported");if("number"!=typeof r||Number.isNaN(r))throw new Constants_1.BooruError("`limit` should be an int");return{site:e,limit:r}}function compareArrays(t,r){return t.filter((t=>r.some((r=>t.toLowerCase()===r.toLowerCase()))))}exports.resolveSite=resolveSite,exports.jsonfy=jsonfy,exports.shuffle=shuffle,exports.randInt=randInt,exports.validateSearchParams=validateSearchParams,exports.compareArrays=compareArrays;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/pi/scraperv212/node_modules/booru/dist/boorus/Booru.js:1:290)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
```.

This bug also affect any kind of linux terminal (ex. Windows Subsystem for Linux, etc.)
Any solutions?
AtoraSuunva commented 2 years ago

Which version of booru and node.js are you using?

Latest (2.5.3) and previous latest (2.5.2) both work for me on linux, wsl, and windows (Node.js v16.6.2 and v17.0.1)

azurenekowo commented 2 years ago

@AtoraSuunva the friend who reported me this error is running node v10.17, maybe that is the problem? I just fired up my linux mint vm w/ node v17 and it works fine...

image

Also, I just figured out that my window subsystem for linux terminal runs node v12... my friend is running Debian as well.. maybe this case is solved.

AtoraSuunva commented 2 years ago

Seems to be it, there's an optional chain operator ?. here https://github.com/AtoraSuunva/booru/blob/master/src/Utils.ts#L69

Support for it starts on Node.js v14, so any version < 14 won't work

I could support lower versions, but v10 is already end-of-life, and v12 is reaching end of life in a few months

https://nodejs.org/en/about/releases/

So it's a better idea to update to node v14 or above than stay on an unsupported node version

azurenekowo commented 2 years ago

@AtoraSuunva thanks for the informative info, hope you a good day