shagu / mtg-browser

Convert MTG Card-Scanner (DelverLens) exports into a simple website with plain image files
MIT License
7 stars 2 forks source link

TypeError: card.name.replaceAll is not a function #2

Open Nimrod-666 opened 2 years ago

Nimrod-666 commented 2 years ago

Hi, i try do do a "make" and i'm getting this error:

myuser@myuser-VirtualBox:~/Downloads/cards/mtg-browser$ make
Preparing Resources
 - Extracting DelverLens Database
 - Copying Card Backup Database
 - Downloading MTGJSON Database
######################################################################################################## 100,0%
rm -rf collection/*
rm -rf www/*
/home/myuser/Downloads/cards/mtg-browser/main.js:108
    const ipattern = `{${card.color}} ${card.name.replaceAll('/', '|')} {${card.types}} (%s)`
                                                  ^

TypeError: card.name.replaceAll is not a function
    at cards.forEach (/home/myuser/Downloads/cards/mtg-browser/main.js:108:51)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/myuser/Downloads/cards/mtg-browser/main.js:68:7)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
make: *** [Makefile:14: core] Error 1

I added a console.log(card); before the line for debugging purposes now and i get:

sandi@sandi-VirtualBox:~/Downloads/cards/mtg-browser$ make
Preparing Resources
 - Extracting DelverLens Database
 - Copying Card Backup Database
 - Downloading MTGJSON Database
rm -rf collection/*
rm -rf www/*
{ id: 57433,
  foil: 0,
  quantity: 1,
  language: '',
  category: 1,
  scryfall: '1ac285cc-6862-4cc3-86ca-5523882855f4',
  multiverse: '177558',
  rarity: 'rare',
  types: 'Instant',
  subtypes: null,
  set: 'PLIST',
  cmc: 1,
  name: 'Burst Lightning',
  color: 'R',
  text:
   'Kicker {4} (You may pay an additional {4} as you cast this spell.)\nBurst Lightning deals 2 damage to any target. If this spell was kicked, it deals 4 damage instead.',
  mana: '{R}',
  date: '2020-09-26',
  setname: 'The List' }
/home/sandi/Downloads/cards/mtg-browser/main.js:109
    const ipattern = `{${card.color}} ${card.name.replaceAll('/', '|')} {${card.types}} (%s)`
                                                  ^

TypeError: card.name.replaceAll is not a function
    at cards.forEach (/home/sandi/Downloads/cards/mtg-browser/main.js:109:51)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/home/sandi/Downloads/cards/mtg-browser/main.js:68:7)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
make: *** [Makefile:14: core] Error 1
shagu commented 2 years ago

Hello, I can't reproduce your issue. I think you're maybe running an old version of node. (https://www.designcise.com/web/tutorial/how-to-fix-replaceall-is-not-a-function-javascript-error)

It works fine on v17.3.0 (archlinux).

Nimrod-666 commented 2 years ago

You're right, i updated to a newer version and the issue disappeared, but now i got another one:

Preparing Resources
 - Extracting DelverLens Database
 - Copying Card Backup Database
 - Downloading MTGJSON Database
######################################################################## 100.0%
rm -rf collection/*
rm -rf www/*
/magic-cardtool/main.js:71
  card.multiverse = jsondata.multiverseId
                             ^

TypeError: Cannot read properties of undefined (reading 'multiverseId')
    at /magic-cardtool/main.js:71:30
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/magic-cardtool/main.js:68:7)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153: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:81:12)
    at node:internal/main/run_main_module:17:47
make: *** [Makefile:14: core] Error 1

I added a debug console log on 'card' before the line where multiverseId is read, and it seems to be this one that crashes the run:

{
  id: 59962,
  foil: 0,
  image: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff e2 02 28 49 43 43 5f 50 52 4f 46 49 4c 45 00 01 01 00 00 02 18 00 00 00 00 02 10 00 00 ... 36728 more bytes>,
  quantity: 1,
  language: '',
  category: 1,
  scryfall: '142bbbe1-4446-4d80-b82d-0df8ef17eac1'
}