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

Incorrect js file extension with --no-scope-hoist #7813

Closed
unbornchikken opened this issue Mar 9, 2022 · 10 comments · Fixed by #8194
Closed

Incorrect js file extension with --no-scope-hoist #7813

unbornchikken opened this issue Mar 9, 2022 · 10 comments · Fixed by #8194

Comments

@unbornchikken
Copy link

unbornchikken commented Mar 9, 2022

image

This is what I get by using the following build command:

parcel build --dist-dir build --no-scope-hoist

Notice the wrong js file name. In the compiled html I get:

<script src="/index.ce910175.js" defer>

So the js file name would go as expected at some point, but it won't get the correct file name when the build gets completed.

It's actually a TypeScript project with index.html + index.ts.

If I remove --no-scope-hoist the js file gets the correct extension. But I don't want hoist, I need to keep the original identifier names intact.

parcel@2.3.2

@mischnic
Copy link
Member

What OS are you using?

@unbornchikken
Copy link
Author

It's Windows.

@mischnic
Copy link
Member

How many cores does your CPU have?

Could you determine what this function returns for you?

export default function getCores(bypassCache?: boolean = false): number {

e.g. by running

$ node -p 'require("@parcel/workers/lib/cpuCount").default()'

in the shell?

@unbornchikken
Copy link
Author

Intel(R) Core(TM) i9-10900 CPU @ 2.80GHz, 2808 Mhz, 10 Core(s), 20 Logical Processor(s)

@mischnic
Copy link
Member

The problem is that when writing the bundles

await new Promise((resolve, reject) =>
pipeline(
res.stream,
outputFS.createWriteStream(

this rename here

isn't awaited but happens sometime afterwards asynchronously. (The whole handleClose callback is called late, it's not just the missing fs.rename callback)

But it doesn't happen at all if Parcel stops the process forcefully:

process.exit(exitCode);

@alexreardon
Copy link

alexreardon commented Mar 31, 2022

I am getting this error after upgrading to parcel@2.4.0 from 2.2.1

Here is the command I am running:

PARCEL_WORKERS=0 parcel build src/index.html --no-cache --no-source-maps --no-autoinstall

So I am seeing this error without --no-scope-hoist and with 0(?) workers (PARCEL_WORKERS=0)

  • macOS 12.3
  • 2.6 GHz 6-Core Intel Core i7

@alexreardon
Copy link

This bug occurs for me every time. A workaround is to manually fix the file names using a script after parcel is finished 😕

@alexreardon
Copy link

For anybody who needs it, here is a little script I am currently running after parcel to fix the incorrect filename additions

import globby from 'globby';
import invariant from 'tiny-invariant';
import { join } from 'path';
import { rename } from 'fs/promises';

// https://regexr.com/6ir3l
const regex = /^(?<correct>.*?)(?<broken>\.\d+)$/;
const distDirectory = join(process.cwd(), './dist');

// parcel bug is causing random digits to be appended to some filenames
// https://github.com/parcel-bundler/parcel/issues/7813
export async function fixParcelFilenames() {
  const files: string[] = await globby(`*`, {
    cwd: distDirectory,
  });

  for (let i = 0; i < files.length; i++) {
    const file = files[i];
    const match = regex.exec(file);

    if (match?.groups?.broken) {
      const correct = match?.groups?.correct;
      invariant(correct, 'expected to have correct file capture group');
      await rename(join(distDirectory, file), join(distDirectory, correct));
      console.log('broken file', file);
      console.log('renamed to', correct);
    }
  }
}

@mischnic
Copy link
Member

mischnic commented Apr 4, 2022

When I got this, the output files were (often) empty, so renaming might not be enough.

Commenting out this line worked for me

process.exit(exitCode);

@mischnic
Copy link
Member

mischnic commented Jun 7, 2022

Node 13.14.0 is working correctly, the next version 14.0.0 has this behaviour. Something regarding the timing of the close event on the createWriteStream() stream has changed.

Potentially nodejs/node@e13a37e49d

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

Successfully merging a pull request may close this issue.

3 participants