rehypejs / rehype-minify

plugins to minify HTML
https://unifiedjs.com
MIT License
90 stars 16 forks source link

TypeError in rehype-minify-whitespace #34

Closed jcayzac closed 4 years ago

jcayzac commented 4 years ago

Hi there,

My site started failing with the following error after I deleted my yarn.lock and regenerated it based on all the latest versions:

TypeError: Cannot read property 'length' of undefined
    at all (node_modules/rehype-minify-whitespace/index.js:112:25)
    at minify (node_modules/rehype-minify-whitespace/index.js:57:12)
    at all (node_modules/rehype-minify-whitespace/index.js:117:14)
    at minify (node_modules/rehype-minify-whitespace/index.js:57:12)
    at all (node_modules/rehype-minify-whitespace/index.js:117:14)
    at minify (node_modules/rehype-minify-whitespace/index.js:57:12)
    at all (node_modules/rehype-minify-whitespace/index.js:117:14)
    at minify (node_modules/rehype-minify-whitespace/index.js:57:12)
    at transform (node_modules/rehype-minify-whitespace/index.js:40:5)
    at wrapped (node_modules/trough/wrap.js:25:19)

I had to remove rehype-preset-minify for now.

{
  "devDependencies": {
    "@types/gh-pages": "^2.0.1",
    "ajv": "^6.12.2",
    "babel-eslint": "^10.0.3",
    "core-js": "^3.4.0",
    "cross-spawn": "^7.0.3",
    "elasticlunr": "^0.9.5",
    "eslint": "^7.1.0",
    "eslint-config-prettier": "^6.5.0",
    "eslint-plugin-prettier": "^3.1.1",
    "fast-glob": "^3.0.4",
    "gh-pages": "^2.1.1",
    "github-slugger": "^1.2.1",
    "hast-util-to-parse5": "^5.1.1",
    "husky": "^4.2.5",
    "lint-staged": "^10.2.9",
    "mdast-util-to-string": "^1.0.6",
    "mermaid.cli": "^0.5.1",
    "node-plantuml": "^0.9.0",
    "npm-run-all": "^4.1.5",
    "parse5": "^6.0.0",
    "prettier": "^2.0.5",
    "redoc-cli": "^0.9.8",
    "rehype-document": "^5.0.0",
    "rehype-format": "^3.0.1",
    "rehype-highlight": "^4.0.0",
    "rehype-katex": "^3.0.0",
    "rehype-preset-minify": "^5.0.2",
    "rehype-retext": "^2.0.3",
    "rehype-stringify": "^8.0.0",
    "remark-autolink-headings": "^6.0.0",
    "remark-bracketed-spans": "^3.0.0",
    "remark-emoji": "^2.0.2",
    "remark-grid-tables": "^2.1.0",
    "remark-math": "^2.0.0",
    "remark-mermaid": "^0.2.0",
    "remark-parse": "^8.0.2",
    "remark-rehype": "^7.0.0",
    "remark-retext": "^4.0.0",
    "remark-sectionize": "^1.1.0",
    "remark-slug": "^6.0.0",
    "remark-toc": "^7.0.0",
    "retext": "^7.0.0",
    "retext-smartypants": "^4.0.0",
    "rimraf": "^3.0.0",
    "serve": "^11.3.2",
    "svgo": "^1.3.0",
    "to-vfile": "^6.0.0",
    "unified": "^9.0.0",
    "unist-builder": "^2.0.3",
    "unist-util-find": "^1.0.1",
    "unist-util-find-all-after": "^3.0.1",
    "unist-util-find-all-between": "^2.0.0",
    "unist-util-visit": "^2.0.0",
    "unist-util-visit-parents": "^3.0.0",
    "vfile-reporter": "^6.0.0",
    "yarn-upgrade-all": "^0.5.2"
  },
  "resolutions": {
    "minimist": "^1.2.5",
    "rehype-minify-whitespace": "^4.0.3"
  }
}
wooorm commented 4 years ago

Hey there!

jcayzac commented 4 years ago

Thanks!

children is undefined, hence the error. I printed out the parent from line 111 and it was { type: 'element', tagName: 'div', properties: { id: 'lunr-search' } }, an element I injected using rehype-document and unist-builder. I guess I just missed the part in Unified's docs about children being required.

Adding a children: [] to the call to unitst-builder fixes my build.

Cheers,

wooorm commented 4 years ago

Ahh, yeah, children is required on elements!

P.S., hastscript can help with create hast elements (unist-builder is a level higher, for HTML you’ll mostly create elements so hastscript is shorter)