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 2: Build does not finish. #6473

Open
JamesAlexanderHill opened this issue Jun 16, 2021 · 11 comments
Open

Parcel 2: Build does not finish. #6473

JamesAlexanderHill opened this issue Jun 16, 2021 · 11 comments

Comments

@JamesAlexanderHill
Copy link

πŸ› bug report

When running npm run p:build the terminal does not finish running the script however it does say ✨ Built in 7.69s and lists the outputted files with their sizes and build time. It feels like it is watching the files instead of building (Something similar to #748 however im not using typescript or angular)

πŸŽ› Configuration (.babelrc, package.json, cli command)

.babelrc does not exist
cli command: parcel build ./src/index.html --target web

package.json below with important stuff

  "web": "dist/index.html",
  "targets": {
    "web": {
      "context": "browser",
      "publicUrl": "./"
    }
  },
  "scripts": {
    "p:serve": "parcel ./src/index.html --target web --open",
    "p:build": "parcel build ./src/index.html --target web",
  },
  "devDependencies": {
    "autoprefixer": "^10.2.6",
    "cross-env": "^7.0.3",
    "npm-run-all": "^4.1.5",
    "parcel": "^2.0.0-beta.3.1",
    "postcss": "^8.3.1",
    "postcss-cli": "^8.3.1",
    "postcss-import": "^14.0.2",
    "tailwindcss": "^2.1.4"
  }
}

πŸ€” Expected Behavior

I would expect the build script to run and then exit or throw an error to allow more scripts to run.

😯 Current Behavior

Currently I run the build script and it runs as expected but it does not finish running the script even tho the /dist directory has all the bundled files.

πŸ’ Possible Solution

Not sure

πŸ”¦ Context

Trying to get Tailwind and Parcel 2 working together. It all works by adding tailwind to the postCSS file however it does not exit the build script correctly

πŸ’» Code Sample

https://github.com/JamesAlexanderHill/tailwind-parcel-val-workshop/tree/integrate-parcel

Branch: integrate-parcel

Run the following:

  • npm i
  • npm run p:build

🌍 Your Environment

Software Version(s)
Parcel ^2.0.0-beta.3.1
Tailwindcss ^2.1.4
Node v14.0.0
npm/Yarn v7.7.6
Operating System Windows 10 Home
@devongovett
Copy link
Member

It should work better with the latest Parcel nightly and Tailwind 2.2. There was a bunch of recent work on both for this.

@JamesAlexanderHill
Copy link
Author

Looks like its working more reliably. I can still recreate this issue by doing the following:

  • npm run build (Successful)
  • npm run serve (Successful)
  • ctrl+c (Exits without error)
  • npm run build (does not exit the build command)
  • ctrl+c (Exits without error)
  • npm run build (Successful)

@basher
Copy link

basher commented Aug 11, 2021

I have the same build not finishing problem with a fresh install of Parcel 2.0.0-rc.0.

parcel build index.html --dist-dir dist/theme-build

Assets are correctly bundled in folder, but Node process doesn't terminate. I need to ctrl+c.

UPDATE:

  • Build not finishing is via a terminal window in VSCode.
  • Running build from CMD prompt or Powershell completes OK.

@astegmaier
Copy link
Contributor

astegmaier commented Aug 16, 2021

I think I may have hit this problem as well. A few observations that may be helpful with debugging:

  • It repros in 2.0.0-rc.0 and the latest nightly (2.0.0-nightly.799 as of 8/16/2021)
  • It only seems to repro on Windows. I have the exact same project on my Mac, and have never seen the parcel build command fail to finish.
  • After you get in a state where the build fails to finish, if you manually kill the parcel build process (e.g. cmd + c), I get in a state where trying to delete the .parcel-cache or dist folders will fail with error EBUSY: resource busy or locked, unlink: C:\...\myproject\.parcel-cache\data.mdb. This error will go away if you restart the terminal from which you ran parcel build
  • I don't see the differences that @basher observed - it will hang consistently when running parcel build regardless of whether I do this in a CMD prompt, Windows Terminal, CMD-inside-VS-Code.
  • I have a minimal repro here.

@astegmaier
Copy link
Contributor

astegmaier commented Aug 18, 2021

In debugging, it seems to be related to a problem in ora on windows (see issues 132 and 135).

This comment from ora issue 135 suggested the problem might be related to setting raw mode:

Problem mostly boiled down to using raw mode twice(on separate ticks) hanged the [process] under windows. Relevant change added to example.js(tested in cmd).

I found that commenting out these lines makes the hang-on-windows disappear:

process.stdin.setRawMode(false);

process.stdin.setRawMode(true);

This probably isn't the right fix, but it is a clue about what is causing it.

@astegmaier
Copy link
Contributor

astegmaier commented Aug 19, 2021

I found that the issue is specific to earlier versions of node (on windows only). Here's what I tested:

  • node 12.18.3 - parcel hangs after running parcel build x
  • node 14.15.4 - no hang
  • node 16.7.0 - no hang

Given this, if anyone hits the issue, the workaround of simply upgrading to node 14+ should be enough. @devongovett - is there a project-wide goal of supporting older version of node earlier than 14?

If we do want to fix this, the issue is that this line in restore-cursor hangs after we call process.exit here.

https://github.com/sindresorhus/restore-cursor/blob/fcc926e89bd18bdc913e6595b1fd1cb5ba3c896f/index.js#L7

cursor-restore is a dependency of cli-cursor, which is a dependency of ora (which renders the spinny).

I think it's somehow related to the fact that writing to the stderr stream is async on windows, but synchronous on POSIX platforms.

There are various things that seem fix the problem on node 12+windows, but they all seem kind of hacky, including:

  • leaving stdin in rawMode on exit (mentioned above)
  • killing the process with process.emit("SIGINT") instead of process.exit
  • removing code in cli.js that ultimately runs stdin.destroy (here)

@mischnic
Copy link
Member

Currently, we support Node 12+:

"node": ">= 12.0.0"
(this mostly influences which Node APIs we use and what the Babel compilation target is)

@andyli
Copy link

andyli commented Mar 1, 2023

Somehow I had the same problem in CI (GitLab CI running on Linux) using docker image node:16-buster and node:18-buster with parcel 2.8.3.

I'm afraid that means the issue affects not only Windows and/or node 12.


update:

Turn out it was the parcel cache. The build exited correctly once I added --no-cache.
I guess the cache contains too many files so it couldn't finish writing them to disk before timeout (1 hour)?

@mischnic
Copy link
Member

mischnic commented Mar 1, 2023

I guess the cache contains too many files so it couldn't finish writing them to disk before timeout (1 hour)?

The cache can currently grow infinitely (as we don't have any garbage collection yet), but it shouldn't cause any slowdowns at build (and many of these files will simply be ignored by Parcel)

@mzihlmann
Copy link

mzihlmann commented May 2, 2023

we currently have the same issue as @andyli in our docker builds. For us the build would hang in 50% of cases in the parcel build step in CI. If the build would run through it would finish in seconds, if it hangs it hangs for more than 1 hour. --log-level error reduced the likelyhood, --no-cache seems to have fixed the issue for us for good. I'm not familiar at all with the parcel codebase, but to me, this sounds like some race-condition / deadlock (log-level might impact timing in critical section somewhere in the caching logic)?

we are running on node:16-alpine with parcel==2.8.3.

@amierzwicki
Copy link

Could be related (although it could be something completely else): parcel-bundler/watcher#159

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

8 participants