parcel-bundler/parcel

If a target name contains a slash, parcel fails with a hard-to-diagnose error message

Open

#9001 opened on May 10, 2023

View on GitHub
 (5 comments) (0 reactions) (0 assignees)JavaScript (44,030 stars) (2,274 forks)batch import
:bug: Bug:pray: Help WantedGood First IssueStale Ignore

Description

A valid target would look like this in package.json:

    "server_commonjs": {
      "isLibrary": true,
      "source": "src/index.ts",
      "optimize": false,
      "context": "node",
      "outputFormat": "commonjs",
      "distDir": "dist/server/commonjs"
    }

When an accident is made using string replace and it looks like this instead:

    "/dist/server_commonjs": {
      "isLibrary": true,
      "source": "src/index.ts",
      "optimize": false,
      "context": "node",
      "outputFormat": "commonjs",
      "distDir": "dist/server/commonjs"
    }

Parcel fails with the quite unhelpful error message:

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

  TypeError: Cannot use 'in' operator to search for 'key' in undefined
      at getJSONSourceLocation (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/unplugged/@parcel-diagnostic-npm-2.8.3-2e1d38a83b/node_modules/@parcel/diagnostic/lib/diagnostic.js:178:19)
      at EntryResolver.resolveEntry (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/unplugged/@parcel-core-npm-2.8.3-1751106c31/node_modules/@parcel/core/lib/requests/EntryRequest.js:214:64)
      at async Object.run (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/unplugged/@parcel-core-npm-2.8.3-1751106c31/node_modules/@parcel/core/lib/requests/EntryRequest.js:75:16)
      at async RequestTracker.runRequest (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/unplugged/@parcel-core-npm-2.8.3-1751106c31/node_modules/@parcel/core/lib/RequestTracker.js:756:20)
      at async AssetGraphBuilder.runEntryRequest (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/unplugged/@parcel-core-npm-2.8.3-1751106c31/node_modules/@parcel/core/lib/requests/AssetGraphRequest.js:816:18)
      at async $b0fd219fea43bcac$export$2e2bcd8739ae039._runFn (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/cache/@parcel-utils-npm-2.8.3-13fd8c7807-69edf3e7c3.zip/node_modules/@parcel/utils/lib/index.js:33579:13)
      at async $b0fd219fea43bcac$export$2e2bcd8739ae039._next (/Users/daniel/Documents/depict/2-depict.ai/browser-tags-v2/.yarn/cache/@parcel-utils-npm-2.8.3-13fd8c7807-69edf3e7c3.zip/node_modules/@parcel/utils/lib/index.js:33572:9)

🚨 Build failed.

Expected behavior: better error message

I figured it out by adding console.log statements to parcel. in EntryRequest in @parcel/core keyPath is built like this

let keyPath = `/targets/${targetName}/source${Array.isArray(target.source) ? `/${i}` : ''}`;

which became very weird due to my accidental added slashes.

Sorry for not filling out the issue template I wanted to be quick, lmk if it's too terrible

Contributor guide