juice icon indicating copy to clipboard operation
juice copied to clipboard

TypeError: Cannot set property length of [object Object] which has only a getter

Open GeoffreyPlitt opened this issue 9 years ago • 4 comments

I'm getting the following error.

My invocation looks like:

const url = 'file:///vagrant/frontend/emails/'
juice.juiceContent(html, {url: url}, (err, html) => {...

And the HTML has a stylesheet with href pointing to a relative path with parent folder using double-dots ("../styles/style.css")

I get:

    Uncaught TypeError: Cannot set property length of [object Object] which has only a getter
      at core.Node.insertBefore (/vagrant/node_modules/juice2/node_modules/jsdom/lib/jsdom/level1/core.js:553:30)
      at null.<anonymous> (/vagrant/node_modules/juice2/node_modules/jsdom/lib/jsdom/level2/events.js:332:20)
      at proto.(anonymous function) [as insertBefore] (/vagrant/node_modules/juice2/node_modules/jsdom/lib/jsdom/utils.js:23:26)
      at core.Node.appendChild (/vagrant/node_modules/juice2/node_modules/jsdom/lib/jsdom/level1/core.js:671:17)
      at /vagrant/node_modules/juice2/lib/juice.js:376:18
      at Array.forEach (native)
      at /vagrant/node_modules/juice2/lib/juice.js:372:20
      at cbListener (/vagrant/node_modules/juice2/node_modules/pend/index.js:45:5)
      at Array.forEach (native)
      at onCb (/vagrant/node_modules/juice2/node_modules/pend/index.js:41:17)
      at /vagrant/node_modules/juice2/lib/juice.js:366:9
      at fs.js:334:14
      at /vagrant/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/graceful-fs.js:104:5
      at FSReqWrap.oncomplete (fs.js:95:15)

GeoffreyPlitt avatar Apr 28 '15 00:04 GeoffreyPlitt

I'm getting the same coming at through inlineContent. It looks like document.querySelectorAll(sel) is having the problem. Stopped just before the error, I can perform document.querySelector(sel) and it returns a result, but document.querySelectorAll(sel) consistently returns the "Uncaught TypeError: Cannot set property length of [object Object] which only has a getter".

My guess is that it is a problem with "jsdom" which blesses your document (or fragment) with DOM properties and functions. It must be an error with the implementation of document.querySelectorAll

ReinsBrain avatar Jun 18 '15 22:06 ReinsBrain

I have the same issue. It doesn't work on node 0.12, maybe because of the outdated version of jsdom. It's currently at v4.0 now.

ryandao avatar Jun 29 '15 10:06 ryandao

Getting this error as well, halp :disappointed:

jonscottclark avatar Jul 14 '15 13:07 jonscottclark

Well, I suck. Tests failed..

I had originally chosen this because it had the applyLinksToStyleTags option. But I ended up digging into the original https://github.com/Automattic/juice repo and realized that by using its juiceFile method, it will fetch remote resources.

I would recommend using the original repo as the maintainers are actively patching it, while it seems that this fork is no longer maintained, and is becoming problematic with jsdom advancing so rapidly and its current versions only working with iojs. Meanwhile, the original repo is using cheerio and doesn't seem to be having any major dependency issues.

jonscottclark avatar Jul 14 '15 14:07 jonscottclark