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

Failed to parse URL from [object Object] #144

Closed
lookfirst opened this issue Jan 7, 2022 · 16 comments
Closed

Failed to parse URL from [object Object] #144

lookfirst opened this issue Jan 7, 2022 · 16 comments
Labels
bug Something isn't working

Comments

@lookfirst
Copy link

I just tried to upgrade to v2 and hit /, which I have mapped to a 404 (but any of my previously working endpoints fail as well). I have no idea why this is failing now.

My code is dead simple:

2022-01-07 12-06-07

The error is:

2022-01-07 12-02-55

Seems like there are two bits here... a problem with miniflare and giving feedback to your upstream dependency undici to display a more helpful error than trying to blindly concat a string and an object.

@DJtheRedstoner
Copy link

Are you using Yarn PnP? This happens for me with Yarn PnP.

@lookfirst
Copy link
Author

@DJtheRedstoner Yes. I filed another issue along those lines too. #143

This is a pretty major regression, surprised nobody tested this.

@mrbbot
Copy link
Contributor

mrbbot commented Jan 14, 2022

Hey everyone! 👋 I've spent most the afternoon trying to debug this and I haven't been able to fix it. Yarn PnP seems pretty cool, but to me at least, it's very opaque and hard to debug. I'll share what I've found so far. I would be very happy to accept a PR fixing this, but I don't think I'm going to spend any more time myself trying to fix this, as it works with npm/pnpm/Yarn 1.


The problem is caused by this line:

if (input instanceof Request) input = input[_kInner];
super(new BaseRequest(input, init));

It looks like 2 versions of @miniflare/core are being loaded, so input is an instance of a Request class from a different @miniflare/core version. This causes our custom-Request class to be passed to undici (via the new BaseRequest constructor), which isn't an instanceof of undici's (Base)Request class, so it just stringifies it as a URL, hence the [object Object].

This can be seen in the .pnp.js file: (NOTE: some of the hashes/versions might be different, this is my development version with uncommitted changes)

.pnp.js
["@miniflare/core", [
  ["npm:2.0.0", {
    "packageLocation": "./.yarn/cache/@miniflare-core-npm-2.0.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/",
    "packageDependencies": [
      ["@miniflare/core", "npm:2.0.0"]
    ],
    "linkType": "SOFT",
  }],
  ["virtual:4612a3e4318f1d4532829ddfea859ddb4033714894b6ebbf06109a0a1089d0526e59f6758bfd5de89902c9d9ec4a226d7928e940dcdb21d9affb89a876898a6c#npm:2.0.0", {
    "packageLocation": "./.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.0.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/",
    "packageDependencies": [
      ["@miniflare/core", "virtual:4612a3e4318f1d4532829ddfea859ddb4033714894b6ebbf06109a0a1089d0526e59f6758bfd5de89902c9d9ec4a226d7928e940dcdb21d9affb89a876898a6c#npm:2.0.0"],
      ["@iarna/toml", "npm:2.2.5"],
      ["@miniflare/shared", "npm:2.0.0"],
      ["@miniflare/watcher", "npm:2.0.0"],
      ["@types/miniflare__watcher", null],
      ["busboy", "npm:0.3.1"],
      ["dotenv", "npm:10.0.0"],
      ["kleur", "npm:4.1.4"],
      ["set-cookie-parser", "npm:2.4.8"],
      ["undici", "npm:4.12.1"]
    ],
    "packagePeers": [
      "@miniflare/watcher",
      "@types/miniflare__watcher"
    ],
    "linkType": "HARD",
  }],
  ["virtual:b426922761b424d6f41e8750de53fe1bbd08be0031a15530893ce688ab42c2d19a24361dcc8a170fff10c826074fd448e42a18b2df75b625602417ddee5354ef#npm:2.0.0", {
    "packageLocation": "./.yarn/$$virtual/@miniflare-core-virtual-36f87c2a4c/0/cache/@miniflare-core-npm-2.0.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/",
    "packageDependencies": [
      ["@miniflare/core", "virtual:b426922761b424d6f41e8750de53fe1bbd08be0031a15530893ce688ab42c2d19a24361dcc8a170fff10c826074fd448e42a18b2df75b625602417ddee5354ef#npm:2.0.0"],
      ["@iarna/toml", "npm:2.2.5"],
      ["@miniflare/shared", "npm:2.0.0"],
      ["@miniflare/watcher", null],
      ["@types/miniflare__watcher", null],
      ["busboy", "npm:0.3.1"],
      ["dotenv", "npm:10.0.0"],
      ["kleur", "npm:4.1.4"],
      ["set-cookie-parser", "npm:2.4.8"],
      ["undici", "npm:4.12.1"]
    ],
    "packagePeers": [
      "@miniflare/watcher",
      "@types/miniflare__watcher"
    ],
    "linkType": "HARD",
  }]
]],

The first gets used by the miniflare package:

["miniflare", [
  ["npm:2.0.0", {
    "packageLocation": "./.yarn/cache/miniflare-npm-2.0.0-138d8a5ee0-ddcb0178d9.zip/node_modules/miniflare/",
    "packageDependencies": [
      ["miniflare", "npm:2.0.0"]
    ],
    "linkType": "SOFT",
  }],
  ["virtual:ebc911dbdf8f37abd4dca2dced16a945d12f0ef0299f18a05a9e3fb50e0507f0ee90b326660e6d343db4fd3fbed72a138d577eac1b2afc578382fe9fbacf8915#npm:2.0.0", {
    "packageLocation": "./.yarn/$$virtual/miniflare-virtual-4612a3e431/0/cache/miniflare-npm-2.0.0-138d8a5ee0-ddcb0178d9.zip/node_modules/miniflare/",
    "packageDependencies": [
      ...
      ["@miniflare/core", "virtual:4612a3e4318f1d4532829ddfea859ddb4033714894b6ebbf06109a0a1089d0526e59f6758bfd5de89902c9d9ec4a226d7928e940dcdb21d9affb89a876898a6c#npm:2.0.0"],
     ...

...and the second gets used by everything else:

["@miniflare/durable-objects", [
  ["npm:2.0.0", {
    "packageLocation": "./.yarn/cache/@miniflare-durable-objects-npm-2.0.0-f066b4d653-a01cbf6eb4.zip/node_modules/@miniflare/durable-objects/",
    "packageDependencies": [
      ...
      ["@miniflare/core", "virtual:b426922761b424d6f41e8750de53fe1bbd08be0031a15530893ce688ab42c2d19a24361dcc8a170fff10c826074fd448e42a18b2df75b625602417ddee5354ef#npm:2.0.0"],
      ...
    ],
    "linkType": "HARD",
  }]
]],

Patching .pnp.js to log module cache misses also shows this:

  const cacheEntry = entry.cache[modulePath];
- if (cacheEntry) return cacheEntry.exports; // Create a new module and store it into the cache
+ if (cacheEntry) {
+   if (modulePath.includes("@miniflare/core")) console.log("HIT: ", parent.id, "(", request, ")", "\n   ->", modulePath);
+   return cacheEntry.exports; // Create a new module and store it into the cache
+ } else {
+   if (modulePath.includes("@miniflare/core")) console.log("MISS:", parent.id, "(", request, ")", "\n   ->", modulePath);
+ }

I would expect only 1 cache miss, but I see 2:

MISS: .../mf-yarn2/.yarn/cache/@miniflare-cache-npm-2.1.0-b426922761-501a0a5941.zip/node_modules/@miniflare/cache/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
MISS: .../mf-yarn2/.yarn/$$virtual/miniflare-virtual-4612a3e431/0/cache/miniflare-npm-2.1.0-138d8a5ee0-ddcb0178d9.zip/node_modules/miniflare/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-2a535e900b/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/cache/@miniflare-durable-objects-npm-2.1.0-f066b4d653-a01cbf6eb4.zip/node_modules/@miniflare/durable-objects/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/cache/@miniflare-html-rewriter-npm-2.1.0-db6fc88678-798cfa0c2f.zip/node_modules/@miniflare/html-rewriter/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/cache/@miniflare-http-server-npm-2.1.0-efdcf67d42-ea7421b53a.zip/node_modules/@miniflare/http-server/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/cache/@miniflare-web-sockets-npm-2.1.0-1753679fbf-6133c9e650.zip/node_modules/@miniflare/web-sockets/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/cache/@miniflare-web-sockets-npm-2.1.0-1753679fbf-6133c9e650.zip/node_modules/@miniflare/web-sockets/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js
HIT:  .../mf-yarn2/.yarn/cache/@miniflare-scheduler-npm-2.1.0-8921972c4e-21951ce00b.zip/node_modules/@miniflare/scheduler/dist/src/index.js ( @miniflare/core ) 
   -> .../mf-yarn2/.yarn/$$virtual/@miniflare-core-virtual-0ebdd2d7de/0/cache/@miniflare-core-npm-2.1.0-eb145c8dfa-851c85954a.zip/node_modules/@miniflare/core/dist/src/index.js

I've tried defining @miniflare/core as a peerDependency in miniflare but that just causes issues with the installation.

$ yarn
➤ YN0000: ┌ Resolution step
➤ YN0002: │ mf-yarn2@workspace:. doesn't provide @miniflare/core (p4d8e5), requested by miniflare
➤ YN0000: │ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
➤ YN0000: └ Completed in 1s 774ms

$ yarn explain peer-requirements p4d8e5
➤ YN0000: mf-yarn2@workspace:. doesn't provide @miniflare/core, breaking the following requirements:

➤ YN0000: miniflare@npm:2.0.0 [ebc91] → 2.0.0 ✘

Any assistance/PRs would be greatly appreciated 🙂

@mrbbot mrbbot added bug Something isn't working wontfix This will not be worked on help wanted labels Jan 14, 2022
@lookfirst
Copy link
Author

Thanks for looking into this @mrbbot. I've pinged the yarn devs and one has offered to look at this and requested a bare minimal test project.

Added it here: https://github.com/lookfirst/miniflare2-fail

clone, yarn install, yarn dev

As an aside, I don't think 'wontfix' is the right tag for this. It should get fixed.

@mrbbot mrbbot removed the wontfix This will not be worked on label Jan 14, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Jan 14, 2022

Thank you! 🙂 You're right, the help wanted tag is more appropriate.

@merceyz
Copy link

merceyz commented Jan 14, 2022

@mrbbot Based on the .pnp.js snippets you provided the reason you're getting multiple instances of @miniflare/core is because one of them has access to @miniflare/watcher while the other doesn't. These instances are referred to as virtual packages, more details here https://yarnpkg.com/advanced/lexicon/#virtual-package.


If you run the following command in the repro @lookfirst provided

yarn info @miniflare/core --virtuals -AR --dependents
├─ @miniflare/core@npm:2.0.0
│  ├─ Instances: 2
│  ├─ Version: 2.0.0
│  │
│  ├─ Dependents
│  │  └─ miniflare@npm:2.0.0
│  │
│  └─ Dependencies
│     ├─ @iarna/toml@npm:^2.2.5 → npm:2.2.5
│     ├─ @miniflare/shared@npm:2.0.0 → npm:2.0.0
│     ├─ busboy@npm:^0.3.1 → npm:0.3.1
│     ├─ dotenv@npm:^10.0.0 → npm:10.0.0
│     ├─ kleur@npm:^4.1.4 → npm:4.1.4
│     ├─ set-cookie-parser@npm:^2.4.8 → npm:2.4.8
│     └─ undici@npm:4.12.1 → npm:4.12.1
│
├─ @miniflare/core@npm:2.0.0 [1134e]
│  ├─ Version: 2.0.0
│  │
│  ├─ Dependents
│  │  ├─ @miniflare/cache@npm:2.0.0
│  │  ├─ @miniflare/durable-objects@npm:2.0.0
│  │  ├─ @miniflare/html-rewriter@npm:2.0.0
│  │  ├─ @miniflare/http-server@npm:2.0.0
│  │  ├─ @miniflare/scheduler@npm:2.0.0
│  │  └─ @miniflare/web-sockets@npm:2.0.0
│  │
│  └─ Peer dependencies
│     ├─ @miniflare/[email protected] → ✘
│     └─ @types/miniflare__watcher@* → ✘
│
└─ @miniflare/core@npm:2.0.0 [b6ef1]
   ├─ Version: 2.0.0
   │
   ├─ Dependents
   │  └─ miniflare@npm:2.0.0 [6ad88]
   │
   └─ Peer dependencies
      ├─ @miniflare/[email protected] → npm:2.0.0
      └─ @types/miniflare__watcher@* → ✘

you can see that the following list of packages doesn't provide @miniflare/[email protected] as requested by @miniflare/core@npm:2.0.0

@miniflare/cache@npm:2.0.0
@miniflare/durable-objects@npm:2.0.0
@miniflare/html-rewriter@npm:2.0.0
@miniflare/http-server@npm:2.0.0
@miniflare/scheduler@npm:2.0.0
@miniflare/web-sockets@npm:2.0.0

Alternatively you can also get that list from yarn explain peer-requirements

yarn explain peer-requirements | grep "doesn't" | grep @miniflare/core | grep -v "@types"
➤ YN0000: p1b6c0 → @miniflare/cache@npm:2.0.0 doesn't provide @miniflare/watcher to @miniflare/core
➤ YN0000: p17fca → @miniflare/durable-objects@npm:2.0.0 doesn't provide @miniflare/watcher to @miniflare/core
➤ YN0000: p676bc → @miniflare/html-rewriter@npm:2.0.0 doesn't provide @miniflare/watcher to @miniflare/core
➤ YN0000: p49228 → @miniflare/http-server@npm:2.0.0 doesn't provide @miniflare/watcher to @miniflare/core
➤ YN0000: p8ea86 → @miniflare/scheduler@npm:2.0.0 doesn't provide @miniflare/watcher to @miniflare/core
➤ YN0000: p8cbaa → @miniflare/web-sockets@npm:2.0.0 doesn't provide @miniflare/watcher to @miniflare/core

@lookfirst
Copy link
Author

Probably easiest to just move watcher into a dependency for core. @mrbbot need a PR?

@mrbbot mrbbot closed this as completed in d8fb3d6 Jan 14, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Jan 14, 2022

Just fixed! 👍 That's exactly what I did. 🙂 Thanks @merceyz for explaining this, that does make sense.

@mrbbot mrbbot added v2.1.0 and removed help wanted labels Jan 14, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Jan 14, 2022

Hey! 👋 I've just released version 2.1.0 including a fix for this. You can find the full changelog here.

@lookfirst
Copy link
Author

Confirmed with my production worker. Thanks!

@rennokki
Copy link

@mrbbot The issue got back to life with the latest 2.3.0. I think it's based on the fact the undici package got upgraded to 4.13.0. Miniflare v2.2.0 works perfectly fine.

@eric-naguras
Copy link

I just upgrade to 2.4.0 and now I have this issue too.

@rennokki
Copy link

rennokki commented Apr 4, 2022

@mrbbot Still can't upgrade to 2.4.0 either.

@eric-naguras 2.3.0 introduced the issue, 2.2.x should work well.

@mrbbot
Copy link
Contributor

mrbbot commented Apr 4, 2022

Hey @rennokki! Which package manager are you using? Assuming npm, would you be able to try deleting your node_modules directory and package-lock.json file (taking a backup), then running npm install again? I've seen some issues in the past where an old version sticks around after an upgrade and causes this problem.

@eric-naguras
Copy link

@mrbbot I did exactly what you suggested (deleting all dependencies and reinstall) and that solved the issue.

@rennokki
Copy link

rennokki commented Apr 5, 2022

Actually, it worked. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants