parcel icon indicating copy to clipboard operation
parcel copied to clipboard

Parcel v2.9.0 - v2.12.0 with SWC minifier produce invalid bundle when packaged in a Safari extension

Open david-tejada opened this issue 4 months ago • 0 comments

🐛 bug report

I am trying to update the Parcel version in my extension Rango. Parcel versions up to 2.8.3 work fine but starting with 2.9.0 the bundle produced doesn't work when packaged in a Safari extension. The bundles produced for Firefox and Chrome work fine, though.

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

.parcelrc

{
  "extends": "@parcel/config-webextension"
}

package.json

{
  "scripts": {
    "build:mv2-safari": "rimraf dist-mv2-safari && parcel build src/mv2-safari/manifest.json --no-content-hash --dist-dir dist-mv2-safari --no-cache --detailed-report 0"
  }
}

tsconfig.json

{
  "extends": "@sindresorhus/tsconfig/tsconfig.json",
  "compilerOptions": {
    "outDir": "dist",
    "esModuleInterop": true,
    "lib": ["es2022", "DOM", "DOM.Iterable"],
    "strictPropertyInitialization": false,
    "jsx": "react-jsx",
    "noErrorTruncation": true
  },
  "include": ["src/**/*", "tests/**/*"]
}

🤔 Expected Behavior

The produced bundle should work for creating a Safari extension.

😯 Current Behavior

There seems to be two problems here:

The first error I get is:

SyntaxError: Invalid character '\u20ac'

The error happens at this point in the bundle:

var tZ = tC({
  À: "A", // <-- The error happens here
  Á: "A",
  Â: "A",
  Ã: "A",
  Ä: "A",
  // ...
});

That variable is used here:

function sA(e) {
  return (e = i7(e)) && e.replace(eh, tZ).replace(eD, "");
}

If I remove the variable tZ and replace the return statement with return e that problem goes away. The same happens if I run parcel with the flag --no-optimize.

But then I get another error:

Error: Could not resolve bundle with id jkYZu

Searching in the bundle for that identifier this is the only place it appears:

rk = v("kdqLU").getBundleURL("3hxsg") + v("bq5he").resolve("jkYZu");

Maybe this is related to #9972, although this error also happens when running with --no-scope-hoist.

💁 Possible Solution

While writing this issue I realized that the problem goes away if I use @parcel/optimizer-terser as suggested here.

david-tejada avatar Oct 05 '24 09:10 david-tejada