parcel-bundler / parcel

The zero configuration build tool for the web. 📦🚀
https://parceljs.org
MIT License
43.29k stars 2.25k forks source link

Build fails with multiple source globs #9713

Open rmmh opened 2 months ago

rmmh commented 2 months ago

🐛 bug report

Building with the new (in canary) feature of package.json source glob patterns breaks in some conditions with custom file types.

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

parcel@2.0.0-canary.1591, see Code Sample for full repro script.

🤔 Expected Behavior

npx parcel build succeeds.

😯 Current Behavior

🚨 Build failed.

Error: Cannot use 'in' operator to search for 'key' in undefined

  TypeError: Cannot use 'in' operator to search for 'key' in undefined
      at getJSONHighlightLocation (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/diagnostic/lib/diagnostic.js:165:19)
      at getJSONSourceLocation (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/diagnostic/lib/diagnostic.js:207:11)
      at EntryResolver.resolveEntry (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/core/lib/requests/EntryRequest.js:228:62)
      at async Object.run (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/core/lib/requests/EntryRequest.js:57:16)
      at async RequestTracker.runRequest (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/core/lib/RequestTracker.js:777:20)
      at async AssetGraphBuilder.runEntryRequest 
  (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/core/lib/requests/AssetGraphRequest.js:344:18)
      at async $dad2a694f9c45026$export$2e2bcd8739ae039._runFn 
  (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/utils/lib/index.js:34004:13)
      at async $dad2a694f9c45026$export$2e2bcd8739ae039._next 
  (/home/ryan/repro/node_modules/parcel/node_modules/@parcel/utils/lib/index.js:33997:9)

💁 Possible Solution

It seems the multiple source logic from package.json is buggy.

🔦 Context

I'm using parcel to process HTML templates for another tool to render.

💻 Code Sample

tiny repro script:

#!/bin/bash
set -exu
mkdir repro
cd repro
cat > package.json <<EOF
{
  "name": "parcel-multi-repro",
  "source": [
    "*.tmpl",
    "*.html"
  ]
}
EOF
cat > .parcelrc <<EOF
{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.tmpl": [
      "@parcel/transformer-posthtml",
      "@parcel/transformer-html",
    ],
  },
}
EOF
touch a.tmpl b.tmpl c.html
npm i parcel@2.0.0-canary.1591
npx parcel build

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-canary.1591+fcc6b5963
Node v20.12.2
npm/Yarn 10.5.2
Operating System Ubuntu 22.04.4 LTS (x86_64)
TechQuery commented 3 weeks ago

There's no error with parcel@2.12.0, but nothing outputs: https://github.com/parcel-bundler/parcel/discussions/8896#discussioncomment-9909332