Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

wrangler binary is not complete when installing using npm #2148

Closed
hrz6976 opened this issue Dec 4, 2021 · 2 comments · Fixed by #2149 or #2159
Closed

wrangler binary is not complete when installing using npm #2148

hrz6976 opened this issue Dec 4, 2021 · 2 comments · Fixed by #2149 or #2159
Labels
bug Something isn't working

Comments

@hrz6976
Copy link
Contributor

hrz6976 commented Dec 4, 2021

🐛 Bug report

Describe the bug

After an installation with npm, wrangler gave me this error:

Error: spawnSync C:\Users\{user}\.wrangler\bin\wrangler ENOENT

Digging into this, I found the wrangler binary in {user}/.wrangler is smaller than what it should be (7192KB/13646KB). Wrangler worker fine after substituting the binary from https://workers.cloudflare.com/get-npm-wrangler-binary/1.19.5/x86_64-pc-windows-msvc.

However, I did not encounter this issue when configuring wrangler on my mac days before. Maybe it is something with the network connection?

Reproduce the bug

A list of steps to reproduce the bug.

run npm i @cloudflare/wrangler -g

Expected behavior

wrangler binary should be complete and running.

Environment and versions

Fill out the following information about your environment.

  • operating system: Windows 10 Pro x64 21H2
  • output of wrangler -V: 1.19.5
  • output of node -v: v14.15.1
  • content of wrangler.toml: not required to reproduce
@hrz6976 hrz6976 added the bug Something isn't working label Dec 4, 2021
@hrz6976
Copy link
Contributor Author

hrz6976 commented Dec 4, 2021

This might be the cause binary-install.js, L94

As mentioned in this stackoverflow post, you may end up with an incomplete file when simply calling axios(responseType: "stream").then().

Here's a code snippet to replicate this:

const tar = require("tar");
const axios = require("axios");

axios({ url:"https://workers.cloudflare.com/get-npm-wrangler-binary/1.19.5/x86_64-pc-windows-msvc", responseType: "stream" })
.then(res => { res.data.pipe(tar.x({strip:1, C:"f1"}));})
.then(() => { console.log("done 1"); })


axios({ url:"https://workers.cloudflare.com/get-npm-wrangler-binary/1.19.5/x86_64-pc-windows-msvc", responseType: "stream" })
.then( res=> {
    const writer = tar.x({strip:1, C:"f2"});
    //ensure that the user can call `then()` only when the file has
    //been downloaded entirely.
    return new Promise((resolve, reject) => {
      res.data.pipe(writer);
      let error = null;
      writer.on('error', err => {
        error = err;
        writer.close();
        reject(err);
      });
      writer.on('close', () => {
        if (!error) {
          resolve(true);
        }
        //no need to call the reject here, as it will have been called in the
        //'error' stream;
      });
    });
}).then(() => { console.log("done 2"); })

@threepointone
Copy link
Contributor

This is great work, thanks for the detailed bug report @12f23eddde, and following up with the detailed bug fix. I believe you're right.

threepointone pushed a commit that referenced this issue Dec 13, 2021
@threepointone threepointone mentioned this issue Dec 16, 2021
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants