parcel icon indicating copy to clipboard operation
parcel copied to clipboard

2.6.1 - 2.6.2: build error @parcel/compressor-raw: Cannot read properties of undefined (reading 'on')

Open aldrakos opened this issue 2 years ago • 16 comments

🐛 bug report

After trying to update to parcel 2.6.1 and 2.6.2, when trying to build we get an error of @parcel/compressor-raw: Cannot read properties of undefined (reading 'on') . It's an error that happens when packaging different types of files (from .js to .ico to image assets)). Everything works fine on parcel 2.6.0.

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

We're using the following .parcelrc:

{
  "extends": "@parcel/config-default",
  "transformers": {
    "*.{js,mjs,jsx,cjs,ts,tsx}": [
      "@parcel/transformer-js",
      "@parcel/transformer-react-refresh-wrap"
    ]
  }
}

🤔 Expected Behavior

After updating to parcel 2.6.1 or 2.6.2, build completes succesfully.

😯 Current Behavior

After updating to parcel 2.6.1 or 2.6.2, build will most of the time error with message: Packaging index.[hash].js... @parcel/compressor-raw: Cannot read properties of undefined (reading 'on') On few occassions, re-running build will complete ok.

aldrakos avatar Jun 27 '22 17:06 aldrakos

Maybe a weird dependency issue? Try deleting your lock file and node_modules and reinstalling.

devongovett avatar Jul 03 '22 21:07 devongovett

If that doesn't help, please provide a reproduction.

2.6.0 working fine sounds like yet another regression of https://github.com/parcel-bundler/parcel/pull/8194 / https://github.com/parcel-bundler/parcel/pull/8235...

mischnic avatar Jul 03 '22 21:07 mischnic

Can't really provide a reproduction as I'm not fully sure why it happens on our build. Attaching a screenshot of the error received. Not always the same file that throws the error and sometimes build succeeds. Tried deleting parcel cache, node modules, package-lock.json and reinstalling and trying again multiple times.

Screenshot 2022-07-06 175617

aldrakos avatar Jul 06 '22 17:07 aldrakos

I just started a parcel project, and I'm having the same issue. I can't say the exact steps to reproduce, since, as it's happening to you, sometimes it builds, sometimes it gives me this error. However, I think it's not related to JS itself because it happens when I modify even a single letter on the main HTML file.

EduMenges avatar Jul 10 '22 11:07 EduMenges

@EduMenges Are you also using Windows?

mischnic avatar Jul 10 '22 14:07 mischnic

@mischnic Yes, I'm using Windows 10. I rolled back to 2.6.0 and no longer got this error.

EduMenges avatar Jul 10 '22 21:07 EduMenges

I rollback parcel to version 2.6.0. I also got No Errors and it is working fine.

basitcodeenv avatar Jul 11 '22 03:07 basitcodeenv

Just to point out that I don't think it's Windows related: I've tried this on WSL2 / Ubuntu as well, deleting all node_modules and cache and running npm install and it's the same errors. I'll try on a unix based system too, but does not seem to be related.

aldrakos avatar Jul 11 '22 14:07 aldrakos

This is quite annoying.. and very inconsistent. I feel like when it starts to happen, if I just keep running it over and over (and getting this error over and over) it eventually fixes itself.

Running parcel 2.6.2 on Windows 10

onionhammer avatar Jul 21 '22 20:07 onionhammer

As I've said: please say which OS you're using, and ideally share a reproduction

mischnic avatar Jul 21 '22 20:07 mischnic

@mischnic apologies - Windows 10

onionhammer avatar Jul 21 '22 20:07 onionhammer

Looking at the offending line:

stream.on('error', err => {
      reject(err);
    });

The error (I think) is that stream is undefined which comes from fs.createReadStream(filePath) in the same file but I've been unable to get an undefined out of createReadStream.

I would say it's about a 50% success rate of running the build with deleting the dist folder between executions and without any code modification each time.

Is there a way to tease out the file path?

Parcel 2.6.2, Node 16.3.0, Windows 11

andywilsonuk avatar Jul 24 '22 17:07 andywilsonuk

@andywilsonuk you could try just sticking in some console.logs in the build, directly modify the file in your node modules

onionhammer avatar Jul 24 '22 18:07 onionhammer

There's only a handful of places where hashStream is used: https://grep.app/search?q=hashStream&filter[repo][0]=parcel-bundler/parcel

When you edit node_modules to add logging, be sure to modify the lib directory of Parcel packages, not src

mischnic avatar Jul 24 '22 19:07 mischnic

Right, I think it's this commit from last month. When I follow up the stack the error is coming from line 79 in that file. Here's an example of the writeStream properties just before line 79:

console: WriteStream {
  path: 'C:\\Code\\dist\\smartsound_WEAPONS_FLAMETHROWER_Long_Heavy_Single_01.ba2bc0e7.mp3.7204.o',
  flags: 'w',
  mode: 438,
  fd: null,
  start: undefined,
  pos: undefined,
  bytesWritten: 146827,
  closed: false,
  _writableState: WritableState {
    objectMode: false,
    highWaterMark: 16384,
    finalCalled: false,
    needDrain: false,
    ending: true,
    ended: true,
    finished: true,
    destroyed: true,
    decodeStrings: true,
    defaultEncoding: 'utf8',
    length: 0,
    writing: false,
    corked: 0,
    sync: false,
    bufferProcessing: false,
    onwrite: [Function: bound onwrite],
    writecb: null,
    writelen: 0,
    afterWriteTickInfo: null,
    buffered: [],
    bufferedIndex: 0,
    allBuffers: true,
    allNoop: true,
    pendingcb: 0,
    constructed: true,
    prefinished: true,
    errorEmitted: false,
    emitClose: true,
    autoDestroy: true,
    errored: null,
    closed: false,
    closeEmitted: false,
    [Symbol(kOnFinished)]: []
  },
  _events: [Object: null prototype] {
    error: [ [Function], [Function: onerror] ],
    close: [ [Function (anonymous)], [Function: onclose] ],
    end: [Function: onend],
    finish: [Function: onfinish]
  },
  _eventsCount: 4,
  _maxListeners: undefined,
  emit: [Function: emit],
  [Symbol(kFs)]: {
    appendFile: [Function: appendFile],
    appendFileSync: [Function: appendFileSync],
    access: [Function: access],
    accessSync: [Function: accessSync],
    chown: [Function (anonymous)],
    chownSync: [Function (anonymous)],
    chmod: [Function (anonymous)],
    chmodSync: [Function (anonymous)],
    close: [Function: close],
    closeSync: [Function: closeSync],
    copyFile: [Function: copyFile],
    copyFileSync: [Function: copyFileSync],
    createReadStream: [Function: createReadStream],
    createWriteStream: [Function: createWriteStream],
    exists: [Function: exists],
    existsSync: [Function: existsSync],
    fchown: [Function (anonymous)],
    fchownSync: [Function (anonymous)],
    fchmod: [Function (anonymous)],
    fchmodSync: [Function (anonymous)],
    fdatasync: [Function: fdatasync],
    fdatasyncSync: [Function: fdatasyncSync],
    fstat: [Function (anonymous)],
    fstatSync: [Function (anonymous)],
    fsync: [Function: fsync],
    fsyncSync: [Function: fsyncSync],
    ftruncate: [Function: ftruncate],
    ftruncateSync: [Function: ftruncateSync],
    futimes: [Function: futimes],
    futimesSync: [Function: futimesSync],
    lchown: [Function (anonymous)],
    lchownSync: [Function (anonymous)],
    lchmod: [Function (anonymous)],
    lchmodSync: [Function (anonymous)],
    link: [Function: link],
    linkSync: [Function: linkSync],
    lstat: [Function (anonymous)],
    lstatSync: [Function (anonymous)],
    lutimes: [Function: lutimes],
    lutimesSync: [Function: lutimesSync],
    mkdir: [Function: mkdir],
    mkdirSync: [Function: mkdirSync],
    mkdtemp: [Function: mkdtemp],
    mkdtempSync: [Function: mkdtempSync],
    open: [Function: open],
    openSync: [Function: openSync],
    opendir: [Function: opendir],
    opendirSync: [Function: opendirSync],
    readdir: [Function: readdir],
    readdirSync: [Function: readdirSync],
    read: [Function: read],
    readSync: [Function (anonymous)],
    readv: [Function: readv],
    readvSync: [Function: readvSync],
    readFile: [Function: readFile],
    readFileSync: [Function: readFileSync],
    readlink: [Function: readlink],
    readlinkSync: [Function: readlinkSync],
    realpath: [Function: realpath] { native: [Function (anonymous)] },
    realpathSync: [Function: realpathSync] { native: [Function (anonymous)] },
    rename: [Function (anonymous)],
    renameSync: [Function: renameSync],
    rm: [Function: rm],
    rmSync: [Function: rmSync],
    rmdir: [Function: rmdir],
    rmdirSync: [Function: rmdirSync],
    stat: [Function (anonymous)],
    statSync: [Function (anonymous)],
    symlink: [Function: symlink],
    symlinkSync: [Function: symlinkSync],
    truncate: [Function: truncate],
    truncateSync: [Function: truncateSync],
    unwatchFile: [Function: unwatchFile],
    unlink: [Function: unlink],
    unlinkSync: [Function: unlinkSync],
    utimes: [Function: utimes],
    utimesSync: [Function: utimesSync],
    watch: [Function: watch],
    watchFile: [Function: watchFile],
    writeFile: [Function: writeFile],
    writeFileSync: [Function: writeFileSync],
    write: [Function: write],
    writeSync: [Function: writeSync],
    writev: [Function: writev],
    writevSync: [Function: writevSync],
    Dir: [class Dir],
    Dirent: [class Dirent],
    Stats: [Function: Stats],
    ReadStream: [Function: ReadStream],
    WriteStream: [Function: WriteStream],
    FileReadStream: [Function: ReadStream],
    FileWriteStream: [Function: WriteStream],
    _toUnixTimestamp: [Function: toUnixTimestamp],
    F_OK: 0,
    R_OK: 4,
    W_OK: 2,
    X_OK: 1,
    constants: [Object: null prototype] {
      UV_FS_SYMLINK_DIR: 1,
      UV_FS_SYMLINK_JUNCTION: 2,
      O_RDONLY: 0,
      O_WRONLY: 1,
      O_RDWR: 2,
      UV_DIRENT_UNKNOWN: 0,
      UV_DIRENT_FILE: 1,
      UV_DIRENT_DIR: 2,
      UV_DIRENT_LINK: 3,
      UV_DIRENT_FIFO: 4,
      UV_DIRENT_SOCKET: 5,
      UV_DIRENT_CHAR: 6,
      UV_DIRENT_BLOCK: 7,
      S_IFMT: 61440,
      S_IFREG: 32768,
      S_IFDIR: 16384,
      S_IFCHR: 8192,
      S_IFLNK: 40960,
      O_CREAT: 256,
      O_EXCL: 1024,
      UV_FS_O_FILEMAP: 536870912,
      O_TRUNC: 512,
      O_APPEND: 8,
      F_OK: 0,
      R_OK: 4,
      W_OK: 2,
      X_OK: 1,
      UV_FS_COPYFILE_EXCL: 1,
      COPYFILE_EXCL: 1,
      UV_FS_COPYFILE_FICLONE: 2,
      COPYFILE_FICLONE: 2,
      UV_FS_COPYFILE_FICLONE_FORCE: 4,
      COPYFILE_FICLONE_FORCE: 4
    },
    promises: {
      access: [AsyncFunction: access],
      copyFile: [AsyncFunction: copyFile],
      open: [AsyncFunction: open],
      opendir: [Function: opendir],
      rename: [AsyncFunction: rename],
      truncate: [AsyncFunction: truncate],
      rm: [AsyncFunction: rm],
      rmdir: [AsyncFunction: rmdir],
      mkdir: [AsyncFunction: mkdir],
      readdir: [AsyncFunction: readdir],
      readlink: [AsyncFunction: readlink],
      symlink: [AsyncFunction: symlink],
      lstat: [AsyncFunction: lstat],
      stat: [AsyncFunction: stat],
      link: [AsyncFunction: link],
      unlink: [AsyncFunction: unlink],
      chmod: [AsyncFunction: chmod],
      lchmod: [AsyncFunction: lchmod],

It isn't always the same file but they it seems to always error on an un-optimised mp3 file > 20KB.

andywilsonuk avatar Jul 25 '22 19:07 andywilsonuk

If it's line 79, then https://github.com/parcel-bundler/parcel/pull/8337 hopefully fixes it.

mischnic avatar Jul 26 '22 09:07 mischnic

Its fixed into 2.7.0 or not ?

mewhit avatar Aug 23 '22 11:08 mewhit

I haven't seen any problems building after upgrading to 2.7.0

andywilsonuk avatar Aug 25 '22 08:08 andywilsonuk