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 build hangs on a random file #7585

Closed
rjdellecese opened this issue Jan 20, 2022 · 13 comments
Closed

parcel build hangs on a random file #7585

rjdellecese opened this issue Jan 20, 2022 · 13 comments

Comments

@rjdellecese
Copy link

rjdellecese commented Jan 20, 2022

🐛 bug report

parcel build hangs, on a seemingly random file. My problem sounds identical to the one described in #6760. Passing the --no-optimize flag causes the build to succeed. I've also, through testing different configurations in my .parcelrc, discovered that removing the @parcel/transformer-js transformer allows the build to succeed, too (although the resulting build is unusable). parcel serve works fine.

My project comprises Elm and TypeScript (no .js, and literally one .css file with two lines, both of which are @imports).

🎛 Configuration

package.json excerpt

{
  ...
  "engines": {
    "node": "^17.3.0"
  },
  "source": "src/index.html",
  "browserslist": "> 0.5%, last 2 versions, not dead",
  "pwaManifest": {
    ...
  },
  "devDependencies": {
    ...
    "@parcel/packager-raw-url": "^2.2.1",
    "@parcel/packager-xml": "^2.2.1",
    "@parcel/service-worker": "^2.2.1",
    "@parcel/transformer-elm": "^2.2.1",
    "elm": "latest-0.19.1",
    "parcel": "^2.2.1",
    "parcel-config-pwa-manifest": "^0.1.0",
    "typescript": "^4.5.4"
    ...
  },
  ...
}

.parcelrc

{
  "extends": ["@parcel/config-default", "parcel-config-pwa-manifest"],
}

🤔 Expected Behavior

parcel build succeeds without incident.

😯 Current Behavior

parcel build hangs indefinitely on a random file.

Screen.Recording.2022-01-20.at.5.49.43.PM.mov

parcel build --no-optimize succeeds. parcel serve works fine.

🔦 Context

I just transitioned this project from Webpack 5. Everything has worked swimmingly, except for this!

💻 Code Sample

Unfortunately, the project in which I'm experiencing this issue is private, and I can't share the source code. I'm also not sure how to narrow the issue down any further than I have, but am more than willing to try if given suggestions on how!

🌍 Your Environment

Software Version(s)
Parcel 2.2.1
Node 17.3.0
npm/Yarn 8.3.0
Operating System macOS Monterey 12.1
@mischnic
Copy link
Member

mischnic commented Jan 20, 2022

parcel build hangs indefinitely on a random file.
parcel build --no-optimize succeeds. parcel serve works fine.

Does removing this line

if (compilerConfig.optimize) code = await minifyElmOutput(code);

in node_modules/@parcel/transformer-elm/lib/ElmTransformer.js prevent the hanging?
If yes, try to reduce the Elm code as much as possible so that you can share it.

I'm also not sure how to narrow the issue down any further than I have

Try removing these things:

  • parcel-config-pwa-manifest
  • Comment out the import to elm (so only build the TS & CSS parts)

@rjdellecese
Copy link
Author

Thank you for your help @mischnic!

Does removing this line ... in node_modules/@parcel/transformer-elm/lib/ElmTransformer.js prevent the hanging?

Removing that line causes the build to fail with an error!

❯ npx parcel build
🚨 Build failed.

@parcel/optimizer-terser: Undefined label scan

  /Users/rjdellecese/code/hab/web-app/node_modules/@lezer/common/dist/index.js:1392:34
    1391 |                     if (!cursor.parent())
  > 1392 |                         break scan;
  >      |                                  ^ Undefined label scan
    1393 |                     if (overlay && !--overlay.depth) {
    1394 |                         let ranges = punchRanges(this.ranges, overlay.ranges);

  💡 It's likely that Terser doesn't support this syntax yet.

Would it still be helpful to try to reduce the Elm code?

@rjdellecese
Copy link
Author

I suppose that this is the line the error is referring to:

https://github.com/lezer-parser/common/blob/dffe4eda89fb46e6672eece613fdd0c9aeb7ad69/src/mix.ts#L183

@lezer/common is a dependency of my application via various CodeMirror modules, e.g. @codemirror/language

@rjdellecese
Copy link
Author

rjdellecese commented Jan 24, 2022

Let me know what else I can do here—happy to open an issue in another repo or do more testing/scope narrowing if that would be helpful. I've already tested with different Elm minification options by modifying the code in node_modules/@parcel/transformer-elm/lib/ElmTransformer.js, so far to no avail (I tried, for example, duplicating the Terser options I had been using via the Webpack plugin that I was previously using).

@mischnic
Copy link
Member

  1. Does

Comment out the import to elm (so only build the TS & CSS parts)

also result into the @parcel/optimizer-terser error?

  1. Try to reduce the Elm code so that you can share it and we can reproduce the hanging. I'm not sure if this is a bug in Elm or Terser.

@rjdellecese
Copy link
Author

  1. Does

Comment out the import to elm (so only build the TS & CSS parts)

also result into the @parcel/optimizer-terser error?

It looks like it does—the exact same error (I also deleted my Main.elm to make extra certain it wasn't being built).

@mischnic
Copy link
Member

Then please also try to simplify the non-Elm parts so that you can share your code

@rjdellecese
Copy link
Author

It seems to have to do with @lezer/common and the use of "browserslist".

Here's a repo demonstrating the issue: https://github.com/rjdellecese/parcel-2-repro.

Let me know what else I can do!

@rjdellecese
Copy link
Author

Actually, there might be more going on here, because just removing the "browserslist" entry from my package.json doesn't stop the build from hanging. But both removing the "browserslist" entry and commenting out the Elm import does allow the build to complete successfully.

I'll keep investigating.

@mischnic
Copy link
Member

👍 Perfect

Upstream swc issue for that terser/lezer problem: swc-project/swc#3366
This was introduced recently when we enabled transpiling of node_modules

@mischnic mischnic added the swc label Jan 27, 2022
@mischnic mischnic removed the swc label Mar 11, 2022
@rjdellecese
Copy link
Author

I wasn’t having any luck isolating the issue any further, beyond that it had something to do with Terser minification. I also found mention of an issue with Terser on the Elm Discourse forum that matched exactly the description of the problem I was encountering, with no apparent resolution (https://discourse.elm-lang.org/t/ot-webpack-terser-build-issue/7606).

So I resolved the problem by forking the Elm transformer in Parcel and replacing Terser as the minifier with SWC (https://swc.rs/docs/configuration/minification), and everything has worked fine since.

At some point I might publish this on npm, but for now this plugin is just local to my project.

Thank you again for the help!

@balazs-lengyel
Copy link

@rjdellecese I'm having the same issue, thank you for narrowing it down.
I haven't found your solution, so this is my first crude attempt (derived from your description): balazs-lengyel@d92237b Do you have any suggestions for improvement?

So I resolved the problem by forking the Elm transformer in Parcel and replacing Terser as the minifier with SWC (https://swc.rs/docs/configuration/minification), and everything has worked fine since.

@ARyaskov
Copy link

ARyaskov commented Aug 17, 2022

I'm experiencing the same Parcel 2.7.0 bug on building PNG files.
Solution: add --log-level error to parcel build command.
It's weird I know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants