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

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

Open
david-tejada opened this issue Oct 5, 2024 · 0 comments

Comments

@david-tejada
Copy link

🐛 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 david-tejada changed the title Parcel v2.9.0 - v2.12.0 produce invalid bundle when packaged in a Safari extension Parcel v2.9.0 - v2.12.0 with SWC minifier produce invalid bundle when packaged in a Safari extension Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant