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

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

Open
danieltroger opened this issue May 10, 2023 · 5 comments · May be fixed by #9905
Open

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

danieltroger opened this issue May 10, 2023 · 5 comments · May be fixed by #9905
Labels
🐛 Bug Good First Issue 🙏 Help Wanted Stale Ignore This issue is exempt from getting flagged as stale and autoremoved

Comments

@danieltroger
Copy link
Contributor

danieltroger commented May 10, 2023

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

@github-actions github-actions bot added the Stale Inactive issues label Nov 6, 2023
@danieltroger
Copy link
Contributor Author

Still reproducible, download, extract, yarn && yarn parcel build

parcel-repro.zip

@github-actions github-actions bot removed the Stale Inactive issues label Nov 6, 2023
@mischnic mischnic added the Stale Ignore This issue is exempt from getting flagged as stale and autoremoved label Nov 6, 2023
@mischnic
Copy link
Member

mischnic commented Nov 6, 2023

Looks like say there's a encodeJSONKeyComponent missing in the string concatenation you mentioned:

/** Sanitizes object keys before using them as <code>key</code> in generateJSONCodeHighlights */
export function encodeJSONKeyComponent(component: string): string {

@sephialaureenciaa
Copy link

Hi, is this done yet? I'd like to contribute to this!

@sephialaureenciaa
Copy link

Hi @mischnic, just to clarify, you're saying the above issue (where a target name contains slash) should not give an error and instead we should wrap the targetName with encodeJSONKeyComponent?

@sephialaureenciaa sephialaureenciaa linked a pull request Aug 11, 2024 that will close this issue
3 tasks
@sephialaureenciaa
Copy link

I've created a PR for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Good First Issue 🙏 Help Wanted Stale Ignore This issue is exempt from getting flagged as stale and autoremoved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants