wshito / asciidoctor-chunker

The utility to create chunked HTML files from the single HTML generated by Asciidoctor.
MIT License
25 stars 7 forks source link

Failure to chunk with Node.js v18.2.0 and npm 8.10.0 #38

Closed johnthad closed 2 years ago

johnthad commented 2 years ago

I have been running asciidoctor-chunker 1.0.4 without issue using Node.js v16.15.0 and npm 8.5.5.

When I try switching to Node.js v18.2.0 and npm 8.10.0, I get the following errors:

$ $NVM_BIN/asciidoctor-chunker ./documentation/web9manual.html --titlePage Introduction -o manual

/Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/node_modules/cheerio/lib/api/attributes.js:99
        : getAttr(this[0], name, this.options.xmlMode);
                                              ^

TypeError: Cannot read properties of undefined (reading 'xmlMode')
    at Cheerio.attr (/Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/node_modules/cheerio/lib/api/attributes.js:99:47)
    at Element.<anonymous> (file:///Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/src/DOM.mjs:687:22)
    at LoadedCheerio.each (file:///Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/node_modules/cheerio/lib/esm/api/traversing.js:461:26)
    at getLocalFiles (file:///Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/src/DOM.mjs:685:49)
    at file:///Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/src/DOM.mjs:699:3
    at main (file:///Users/thad/.nvm/versions/node/v18.2.0/lib/node_modules/asciidoctor-chunker/src/index.mjs:45:42)

Node.js v18.2.0

I switch back to Node.js v16.15.0 and npm 8.5.5 and all works fine.

wshito commented 2 years ago

I have confirmed the same issue. I am working on it but it needs the complete rewrite on the code related to the DOM manipulation. So it might take for a while.

I suppose the pre-built script should work without a problem since the issue is due to the update in Cheerio package.

johnthad commented 2 years ago

Thanks for the feedback. I thought that had something to do with DOM when I saw import { Cheerio } from '../node_modules/cheerio/lib/cheerio.js'; in DOM.mjs. This was added in 1.0.3, which explains why I now must run asciidoctor-chunker from global vs the project. (BTW, on a different machine yesterday I saw the same error with Node v16.15.0 and npm 8.5.5. I've not run that down yet.)

Ideally I'd like to run asciidoctor-chunker locally, from the project. I notice that when cheerio is installed, it includes node_modules/parse5. However when asciidoctor-chunker installs its node_modules folder is empty. That's why it must run globally, so that import { Cheerio } from '../node_modules/cheerio/lib/cheerio.js'; resolves. As a workaround, I've written a shell script that copies node_modules/cheerio to node_modules/asciidoctor-chunker/node_modules before running asciidoctor_chunker. That works with the latest Node.js & npm, and might be the quickest solution.

I'm out until next week but I'll try to follow up (on yet another Mac) when I can.

johnthad commented 2 years ago

Oops! I didn't mean to close this.

wshito commented 2 years ago

Yes, you nailed down the problem right! I have been using the constructor of Cheerio object that is not public. So I had to import it from the locally installed package.

It was the workaround as the Cheerio project changed the API when they made the major upgrade. I didn't want to rewrite the whole thing.

Now, I give up on tweaking around. I will try to rewrite the code fundamentally so to conform the latest API of Cheerio.

andilem commented 2 years ago

Any news on this? I don't want to install it globally, so this project is currently completely unusable for me.

wshito commented 2 years ago

@andilem, about 80% of work is done. But I am currently occupied with other obligations so please be patient for the last 20% to be done.

Meanwhile you can download and use the pre-built script from the Release section. Sorry for the inconvenience.

wshito commented 2 years ago

Sorry for kept you waiting for such a long time. I have just released the latest version 1.0.5!

johnthad commented 2 years ago

That works for me. Thank you.