schwarzdavid / bootstrap-email

MIT License
27 stars 11 forks source link

Crash when trying any example - cheerio TypeError: Cannot use 'in' operator to search for 'length' in false #29

Open gslender opened 2 years ago

gslender commented 2 years ago

Not sure what the issue is, but cannot get any examples to work at all...

TypeError: Cannot use 'in' operator to search for 'length' in false
at initialize (/Users/gslender/Documents/Development/web_test/node_modules/cheerio/lib/load.js:105:28)
at Function.unwrap (/Users/gslender/Documents/Development/web_test/node_modules/bootstrap-email/src/lib/ElementHelper.js:100:26)
at Element.<anonymous> (/Users/gslender/Documents/Development/web_test/node_modules/bootstrap-email/src/lib/ContentCompiler.js:63:19)
at LoadedCheerio.each (/Users/gslender/Documents/Development/web_test/node_modules/cheerio/lib/api/traversing.js:519:26)
at ContentCompiler.div (/Users/gslender/Documents/Development/web_test/node_modules/bootstrap-email/src/lib/ContentCompiler.js:59:12)
at BootstrapEmail._compileHtml (/Users/gslender/Documents/Development/web_test/node_modules/bootstrap-email/src/BootstrapEmail.js:271:20)
at BootstrapEmail.compile (/Users/gslender/Documents/Development/web_test/node_modules/bootstrap-email/src/BootstrapEmail.js:191:8)
at BootstrapEmail.compileAndSave (/Users/gslender/Documents/Development/web_test/node_modules/bootstrap-email/src/BootstrapEmail.js:205:24)
at Object.<anonymous> (/Users/gslender/Documents/Development/web_test/test.js:31:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47

Node.js v18.0.0
gslender commented 2 years ago

Example that I'm using (of which card.html is the file in the project's test folder)

const BootstrapEmail = require('bootstrap-email');
const bootstrapEmail = new BootstrapEmail(__dirname+'/card.html');
bootstrapEmail.compileAndSave(__dirname+'/e-card.html');
gslender commented 2 years ago

I also tried node v14 and earlier versions of your package and nothing works, which means either I'm doing something majorly incorrect, or there is some environmental dependency that isn't obvious.

Any tips?

manuel-schoebel commented 2 years ago

same issue for us as well, would be cool to get some insights 😅

To replicate:

https://codesandbox.io/s/node-js-forked-eby4cz?file=/src/index.js:68-77

manuel-schoebel commented 2 years ago

We were able to somewhat fix it at the first glance by using cheerio 0.22.0 - ofc that might lead to other side effects we have not uncovered. But might be worth a try.

// package.json
{
  "name": "node-js",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "nodemon src/index.js localhost 8080"
  },
  "dependencies": {
    "express": "4.16.4",
    "bootstrap-email": "1.2.9",
    "cheerio": "0.22.0"
  },
  "devDependencies": {
    "nodemon": "1.18.4"
  },
  "resolutions": {
    "cheerio": "0.22.0"
  },
  "keywords": []
}
gslender commented 2 years ago

Interesting that in the repo package.json it refers to cheerio v1.0.0-rc.10 and yet cheerio v1.0.0-rc.11 is the latest

Perhaps that's the issue ??

gslender commented 2 years ago

I've moved on and avoided using the package at this point as without any feedback, I can't invest more time trying to work on this when I've got so much more to do :P

manuel-schoebel commented 2 years ago

So it is indeed rc-10 not 0.22.0 - for some reason the code sandbox does weird things. Using resolution to fix it that seems to work.

// package.json
{
  "name": "node-js",
  "version": "1.0.2",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "nodemon src/index.js localhost 8080"
  },
  "dependencies": {
    "bootstrap-email": "1.2.9",
    "cheerio": "1.0.0-rc.10",
    "express": "4.16.4"
  },
  "devDependencies": {
    "nodemon": "1.18.4"
  },
  "resolutions": {
    "cheerio": "1.0.0-rc.10"
  },
  "keywords": []
}
knopkem commented 7 months ago

fixed here: https://www.npmjs.com/package/@knopkem/bootstrap-email

MaikelSC commented 7 months ago

So it is indeed rc-10 not 0.22.0 - for some reason the code sandbox does weird things. Using resolution to fix it that seems to work.

// package.json
{
  "name": "node-js",
  "version": "1.0.2",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "nodemon src/index.js localhost 8080"
  },
  "dependencies": {
    "bootstrap-email": "1.2.9",
    "cheerio": "1.0.0-rc.10",
    "express": "4.16.4"
  },
  "devDependencies": {
    "nodemon": "1.18.4"
  },
  "resolutions": {
    "cheerio": "1.0.0-rc.10"
  },
  "keywords": []
}

Although @knopkem new package works great, I would say this is the right solution. Since it amends the original package without changing it and thus you won't have to detach from it. Bravo @manuel-schoebel on discovering this fix, when there is so little to none information available online and also the owner of this project is not been so responsive. Great tool, apart from this issue.