pkg icon indicating copy to clipboard operation
pkg copied to clipboard

Script runs perfectly, but exe returns error

Open ealexandrohin opened this issue 3 years ago • 0 comments

What version of pkg are you using?

5.8.0

What version of Node.js are you using?

v18.7.0

What operating system are you using?

Windows 10

What CPU architecture are you using?

x86_64

What Node versions, OSs and CPU architectures are you building for?

fetched-v18.5.0-win-x64

Describe the Bug

Simple checking in switch if property of error equals needed one.

switch (true) {
  case (err.code === 'EEXIST'):
  // code
  break;
}

And while it runs as script normally, through node ds, the same code packed in exe returns error:

node:fs:201
  return (...args) => ReflectApply(cb, this, args);       
                      ^

TypeError: Cannot read properties of null (reading 'code')
    at C:\snapshot\ds\ds.js
    at FSReqCallback.oncomplete (node:fs:201:23)

Node.js v18.5.0

Expected Behavior

Do not return error.

To Reproduce

Make a async directory via fs and on callback try to get property of error or check its value without if (err) {/*stuff*/} block.

fs.mkdir(path, null, (err) => {
  switch (true) {
    case (err.code === 'EEXIST'): someFunc(); break;
    case (err): console.error(err); break;
    default: someFunc();
  };
});

ealexandrohin avatar Sep 09 '22 16:09 ealexandrohin