Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimizer-htmlnano: contents.filter is not a function #7906

Closed
arneke opened this issue Apr 5, 2022 · 4 comments
Closed

optimizer-htmlnano: contents.filter is not a function #7906

arneke opened this issue Apr 5, 2022 · 4 comments
Labels
✖️ Non-Parcel bug Bugs related to dependencies or plugins

Comments

@arneke
Copy link

arneke commented Apr 5, 2022

🐛 bug report

A particular inline SVG crashes the build. In development it is fine.

🎛 Configuration (.babelrc, package.json, cli command)

{
  "name": "app",
  "version": "1.0.0",
  "description": "Example using Parcel",
  "scripts": {
    "start": "parcel serve index.html",
    "build": "parcel build --public-url . index.html"
  },
  "devDependencies": {
    "eslint": "^8.11.0",
    "eslint-config-airbnb-base": "^15.0.0",
    "eslint-plugin-import": "^2.25.4",
    "parcel": "^2.4.1"
  }
}

🤔 Expected Behavior

Should build

😯 Current Behavior

npm run build

> app@1.0.0 build
> parcel build --public-url . index.html

🚨 Build failed.

@parcel/optimizer-htmlnano: contents.filter is not a function

  TypeError: contents.filter is not a function
  at /app/node_modules/htmlnano/lib/modules/removeComments.js:37:21
  at /app/node_modules/htmlnano/lib/htmlnano.js:139:28
  at traverse (/app/node_modules/posthtml/lib/api.js:105:26)
  at traverse (/app/node_modules/posthtml/lib/api.js:111:5)
  at traverse (/app/node_modules/posthtml/lib/api.js:105:17)
  at traverse (/app/node_modules/posthtml/lib/api.js:111:5)
  at traverse (/app/node_modules/posthtml/lib/api.js:105:17)
  at traverse (/app/node_modules/posthtml/lib/api.js:111:5)
  at traverse (/app/node_modules/posthtml/lib/api.js:105:17)
  at traverse (/app/node_modules/posthtml/lib/api.js:111:5)

💁 Possible Solution

Hacked in

if(!contents.filter) return contents;

in node_modules/htmlnano/lib/modules/removeComments.js:37

🔦 Context

Want to include an SVG inline instead of moving it around separately.

💻 Code Sample

<!DOCTYPE html>
<html>
  <body>
    <div id="map"><div id="reticle">
        <svg xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;">
          <g transform="matrix(2.17865,0,0,0.78134,-68.8061,-1.61418)">
              <rect x="48.106" y="4.048" width="3.672" height="38.62" style="stroke:rgb(235,235,235);stroke-width:1.22px;"></rect>
          </g>
            <g transform="matrix(2.17865,0,0,0.781978,-68.8061,45.0231)">
              <rect x="48.106" y="4.048" width="3.672" height="38.62" style="stroke:rgb(235,235,235);stroke-width:1.22px;"></rect>
          </g>
            <g transform="matrix(-0.00107121,-2.17865,0.781978,-0.000384488,-1.56582,148.815)">
              <rect x="48.106" y="4.048" width="3.672" height="38.62" style="stroke:rgb(235,235,235);stroke-width:1.22px;"></rect>
          </g>
            <g transform="matrix(-0.00107121,-2.17865,0.781978,-0.000384488,45.2253,148.815)">
              <rect x="48.106" y="4.048" width="3.672" height="38.62" style="stroke:rgb(235,235,235);stroke-width:1.22px;"></rect>
          </g>
      </svg>
    </div></div>
  </body>
</html>

🌍 Your Environment

Software Version(s)
Parcel 2.4.1
Node v16.4.2
npm/Yarn 7.18.1
Operating System OS X 12.2.1
@mischnic mischnic added the ✖️ Non-Parcel bug Bugs related to dependencies or plugins label Apr 5, 2022
@maltsev
Copy link

maltsev commented Apr 5, 2022

Sorry about the bug!

I deprecated this new version of htmlnano (2.0.1). Please use 2.0.0 for the time being until the bug is fixed.

ronnix added a commit to Delegation-numerique-en-sante/mesconseilscovid that referenced this issue Apr 6, 2022
cf. parcel-bundler/parcel#7906

Ce n’est pas une dépendance directe. Avec npm 8.3, on pourrait définir des
"overrides", mais là on est en npm 6.x donc on utilise npm-force-resolutions.
ronnix added a commit to Delegation-numerique-en-sante/mesconseilscovid that referenced this issue Apr 6, 2022
cf. parcel-bundler/parcel#7906

Ce n’est pas une dépendance directe. Avec npm 8.3, on pourrait définir des
"overrides", mais là on est en npm 6.x donc on utilise npm-force-resolutions.
ronnix added a commit to Delegation-numerique-en-sante/mesconseilscovid that referenced this issue Apr 6, 2022
cf. parcel-bundler/parcel#7906

Ce n’est pas une dépendance directe. Avec npm 8.3, on pourrait définir des
"overrides", mais là on est en npm 6.x donc on utilise npm-force-resolutions.
@maltsev
Copy link

maltsev commented Apr 6, 2022

I released the new version of htmlnano (2.0.2) with the bugfix.

@arneke
Copy link
Author

arneke commented Apr 6, 2022

Awesome. It works for me, thank you for your efforts! 👏

@arneke arneke closed this as completed Apr 6, 2022
davidbgk pushed a commit to Delegation-numerique-en-sante/mesconseilscovid that referenced this issue Apr 8, 2022
cf. parcel-bundler/parcel#7906

Ce n’est pas une dépendance directe. Avec npm 8.3, on pourrait définir des
"overrides", mais là on est en npm 6.x donc on utilise npm-force-resolutions.
@sjsouvik
Copy link

sjsouvik commented Sep 3, 2023

I'm also facing something similar issue while trying to build(parcel build) the project. Can someone help?

package.json

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "source": "src/index.html",
  "scripts": {
    "start": "parcel",
    "build": "parcel build",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "parcel": "^2.9.3",
    "process": "^0.11.10"
  },
  "browserslist": "> 0.5%, last 2 versions, not dead"
}

Error:

@parcel/optimizer-htmlnano: Could not resolve module "node:os" from 
"/app/node_modules/cosmiconfig/dist/index.js"

  Error: Could not resolve module "node:os" from "/app/node_modules/cosmiconfig/dist/index.js"
      at NodePackageManager.resolveInternal 
  (/app/node_modules/@parcel/package-manager/lib/index.js:3672:21)
      at NodePackageManager.resolveSync (/app/node_modules/@parcel/package-manager/lib/index.js:3567:29)
      at NodePackageManager.requireSync (/app/node_modules/@parcel/package-manager/lib/index.js:3394:33)
      at m.require (/app/node_modules/@parcel/package-manager/lib/index.js:3410:25)
      at require (node:internal/modules/cjs/helpers:103:18)
      at Object.<anonymous> (/app/node_modules/cosmiconfig/dist/index.js:23:35)
      at Module._compile (node:internal/modules/cjs/loader:1218:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
      at Module.load (node:internal/modules/cjs/loader:1081:32)
      at NodePackageManager.load (/app/node_modules/@parcel/package-manager/lib/index.js:3423:15)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✖️ Non-Parcel bug Bugs related to dependencies or plugins
Projects
None yet
Development

No branches or pull requests

4 participants