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

Using node-fs-extra with pkg (create executables) is causing an error in universalify #901

Closed
Infern1 opened this issue May 7, 2021 · 10 comments
Labels

Comments

@Infern1
Copy link

Infern1 commented May 7, 2021

  • Operating System:
  • Windows Server 2019
  • Node.js version:
  • Node LTS 32bit 14.161.1
  • fs-extra version:
  • 10.0.0

I'm using pkg for creating binaries of my NodeJS program. When running directly via NodeJS everything is working as should. However when I created my executable now with fs-extra it stops:

λ .\web_server.exe            
pkg/prelude/bootstrap.js:1359                                                                                                      
      throw error;                                                                                                                 
      ^                                                                                                                            
                                                                                                                                   
TypeError: Cannot read property 'name' of undefined                                                                                
    at C:\snapshot\\WEB_ServerTs\node_modules\fs-extra\node_modules\universalify\index.js:15:26                               
    at Object.<anonymous> (C:\snapshot\WEB_ServerTs\node_modules\fs-extra\lib\fs\index.js:57:27)                             
    at Module._compile (pkg/prelude/bootstrap.js:1433:22)                                                                          
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1218:10)                                                      
    at Module.load (internal/modules/cjs/loader.js:1047:32)                                                                        
    at Function.Module._load (internal/modules/cjs/loader.js:935:14)                                                               
    at Module.require (internal/modules/cjs/loader.js:1087:19)                                                                     
    at Module.require (pkg/prelude/bootstrap.js:1338:31)                                                                           
    at require (internal/modules/cjs/helpers.js:73:18)                                                                             
    at Object.<anonymous> (C:\snapshot\Linde\WEB_ServerTs\node_modules\fs-extra\lib\index.js:5:6)                                  

I tried to look in index.js from universalify however at least for me it doesn't make sense.

exports.fromCallback = function (fn) {
  return Object.defineProperty(function (...args) {
    if (typeof args[args.length - 1] === 'function') fn.apply(this, args)
    else {
      return new Promise((resolve, reject) => {
        fn.call(
          this,
          ...args,
          (err, res) => (err != null) ? reject(err) : resolve(res)
        )
      })
    }
  }, 'name', { value: fn.name })
}
@RyanZim
Copy link
Collaborator

RyanZim commented May 7, 2021

It seems pkg somehow doesn't provide fs.realpath.native, which is a function we need to add promise support to. As a result, universalify attempts to read fn.name from fs.realpath.native, which is undefined, resulting in the error. What target are you compiling to with pkg?

@Infern1
Copy link
Author

Infern1 commented May 8, 2021

Target for compiling is windows x86

@Infern1
Copy link
Author

Infern1 commented May 10, 2021

fixed in pkg, thanks for pointing out the problem

@quinnturner
Copy link

FYI to others, there's a similar issue when using DataDog Trace.

@aboe026
Copy link

aboe026 commented May 12, 2021

@Infern1, I'm seeing the same error with pkg. Is this a pkg problem then? If so, any idea when that fix will get released? Or the latest pkg release where this wasn't broken?

@aboe026
Copy link

aboe026 commented May 13, 2021

Anecdotally, it seems that I am able to use the latest version of pkg (5.1.0) with the 9.1.0 release of fs-extra without running into this issue, but bumping fs-extra to 10.0.0 causes this error to happen.

@Infern1
Copy link
Author

Infern1 commented May 13, 2021

@Infern1, I'm seeing the same error with pkg. Is this a pkg problem then? If so, any idea when that fix will get released? Or the latest pkg release where this wasn't broken?

So patch is merged in pkg, no clue when they plan to release a new version. At least with the fix in place it is working. Using npm from git

@BenjD90
Copy link

BenjD90 commented Jun 14, 2021

@Infern1 It seams to be release in version 5.2.0 of pkg : https:/vercel/pkg/releases/tag/5.2.0

I still doesn't understand the link with fs-extra, there is not pkg dependency I think ? For now I'll rollback to v 9.1.0

@BenjD90
Copy link

BenjD90 commented Jun 14, 2021

In my case it's the lib async-listener that remove the function realpath.native from fs 😨 , nothing associated to pkg :
https:/othiym23/async-listener/blob/master/index.js#L277

Thank you for the lead.

@donthijackthegit
Copy link

Same for [email protected], I have to downgrade fs-extra to 9.1.0 or I will have the same issue for compiled binary which target is linux.

ZanderOlidan pushed a commit to ZanderOlidan/vue-cli-service-chalkfix that referenced this issue Feb 5, 2024
This reverts commit 34ae6f271a732fab407c42f6259ea4c5baa424d7.

See jprichardson/node-fs-extra#901
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants