davideicardi / live-plugin-manager

Plugin manager and installer for Node.JS
MIT License
225 stars 43 forks source link

Problem inside Electron environment (res.body.pipe is not a function) #13

Open N8th8n8el opened 4 years ago

N8th8n8el commented 4 years ago

I am trying to install a package from a private registry (verdaccio) like this:

let registryHost = ...
let token = ...

let tmpDir: string;
tmpDir = await mkdirTmp();

const manager = new PluginManager({
    cwd: tmpDir,
    pluginsPath: tmpDir,
    npmRegistryUrl: registryHost,
    npmRegistryConfig: {
        auth: {
            token: token
        }
    }
});

await manager.install('mypackage');

but it throws this error:

TypeError: res.body.pipe is not a function
    at Promise (httpUtils.js:65)
    at Promise (<anonymous>)
    at Object.<anonymous> (httpUtils.js:63)
    at Generator.next (<anonymous>)
    at fulfilled (httpUtils.js:4)
    at <anonymous>

Here is the verdaccio log:

verdaccio_1        |  info <-- 172.18.0.1 requested 'GET /PACKAGE_NAME'
verdaccio_1        |  trace--- api middleware using JWT auth token
verdaccio_1        |  trace--- [middleware/allow][access] allow for ç
verdaccio_1        |  trace--- allow access for PACKAGE_NAME
verdaccio_1        |  trace--- [auth/allow_action]: user: undefined
verdaccio_1        |  trace--- [auth/allow_action]: hasPermission? true for user: undefined
verdaccio_1        |  trace--- auth/allow_action: access granted to: undefined
verdaccio_1        |  trace--- allowed access for PACKAGE_NAME
verdaccio_1        |  info --> making request: 'GET https://registry.npmjs.org/PACKAGE_NAME'
verdaccio_1        |  http --> 404, req: 'GET https://registry.npmjs.org/PACKAGE_NAME' (streaming)
verdaccio_1        |  http --> 404, req: 'GET https://registry.npmjs.org/PACKAGE_NAME', bytes: 0/21
verdaccio_1        |  http <-- 200, user: USERNAME(172.18.0.1), req: 'GET /PACKAGE_NAME', bytes: 0/882
verdaccio_1        |  info <-- 172.18.0.1 requested 'GET /PACKAGE_NAME/-/PACKAGE_NAME-0.0.0.tgz'
verdaccio_1        |  trace--- api middleware using JWT auth token
verdaccio_1        |  trace--- [middleware/allow][access] allow for USERNAME
verdaccio_1        |  trace--- allow access for PACKAGE_NAME
verdaccio_1        |  trace--- [auth/allow_action]: user: undefined
verdaccio_1        |  trace--- [auth/allow_action]: hasPermission? true for user: undefined
verdaccio_1        |  trace--- auth/allow_action: access granted to: undefined
verdaccio_1        |  trace--- allowed access for PACKAGE_NAME
verdaccio_1        |  http <-- 200, user: USERNAME(172.18.0.1), req: 'GET /PACKAGE_NAME/-/PACKAGE_NAME-0.0.0.tgz', bytes: 0/18210

Downloading the same package with npm from the cli works. Any idea?

davideicardi commented 4 years ago

But the package you are requesting is cached inside verdaccio? From the logs verdaccio is trying to get it from npm and get a 404. Are you able to download it from verdaccio directly? Do you have the download url of the package?

N8th8n8el commented 4 years ago

Yes it is cached inside verdaccio. npmjs.org is just set as uplink and my private package isn't on there. Also verdaccio responds with a 200 for req: 'GET /PACKAGE_NAME' as you can see from the logs.

Yes I am able to download it directly via npm (npm install mypackage --registry http://localhost:4873)

davideicardi commented 4 years ago

Can you try to enable debug logging to get more info? Live plugin manager uses "debug" module. You can try to run your app using "DEBUG=*" environment variable. Or a more specific filter. I suspect that verdaccio has a slightly different logic not supported by my lib.

On Wed, Sep 4, 2019, 08:50 N8th8n8el notifications@github.com wrote:

Yes it is cached inside verdaccio. npmjs.org is just set as uplink and my private package isn't on there. Also verdaccio responds with a 200 for req: 'GET /PACKAGE_NAME' as you can see from the logs.

Yes I am able to download it directly via npm (npm install mypackage --registry http://localhost:4873)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/davideicardi/live-plugin-manager/issues/13?email_source=notifications&email_token=AAGQEWRTLY6IVDIQE5L4K3LQH5LB7A5CNFSM4IQ2WLS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD52RP7Y#issuecomment-527767551, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGQEWR53T7QQ5DCANR3BO3QH5LB7ANCNFSM4IQ2WLSQ .

N8th8n8el commented 4 years ago

I have no time to test is atm. Will report back whenever I find the time.

danielbuechele commented 4 years ago

I'm running into the same issue. Here is what is happening for me. I wanted to use this package in an Electron environment. This means fetch as a browser API is available and node-fetch just returns the native browser implementation instead. When it comes to piping streams node-fetch and browser's fetch are implemented differently, which causes the problem.

davideicardi commented 4 years ago

@N8th8n8el Are you also inside an Electron environment or similar?

@danielbuechele Can you try to send me some steps to reproduce the problem?

N8th8n8el commented 4 years ago

Yes I was.
Version: "electron": "1.8.2"