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

wrangler dev with durable object configured in wrangler.toml fails in miniflare #172

Closed
nksaraf opened this issue Dec 28, 2021 · 6 comments · Fixed by #173
Closed

wrangler dev with durable object configured in wrangler.toml fails in miniflare #172

nksaraf opened this issue Dec 28, 2021 · 6 comments · Fixed by #173

Comments

@nksaraf
Copy link

nksaraf commented Dec 28, 2021

Usage: miniflare [script] [options]

Core Options:
...

Durable Objects Options:
 -o, --do                Durable Object to bind [array:NAME=CLASS[@MOUNT]]
     --do-persist        Persist Durable Object data (to optional path) [boolean/string]

Unexpected option: --do EXAMPLE_CLASS

I think the class name is not being passed, eg. from miniflare docs:

$ miniflare --do OBJECT1=Object1 --do OBJECT2=Object2

This is my wrangler.toml file:

[durable_objects]
bindings = [
  { name = "EXAMPLE_CLASS", class_name = "DurableObjectExample" } # Binding to our DurableObjectExample class
]

Tried to debug the command running with miniflare:

Users/nikhilsaraf/.fnm/node-versions/v17.1.0/installation/bin/node
/Users/nikhilsaraf/garage/vinxi/vinxi/node_modules/.pnpm/miniflare@2.0.0-rc.4/node_modules/miniflare/dist/src/cli.js
../../../../../../../var/folders/vy/5v99851s36lfnhhyv0xnzr1r0000gn/T/tmp-79777-HunGk45rvLoj/worker.js
--watch
--wrangler-config
/Users/nikhilsaraf/garage/vinxi/vinxi/node_modules/.pnpm/wrangler@0.0.6/node_modules/wrangler/miniflare-config-stubs/wrangler.empty.toml
--env
/Users/nikhilsaraf/garage/vinxi/vinxi/node_modules/.pnpm/wrangler@0.0.6/node_modules/wrangler/miniflare-config-stubs/.env.empty
--package
/Users/nikhilsaraf/garage/vinxi/vinxi/node_modules/.pnpm/wrangler@0.0.6/node_modules/wrangler/miniflare-config-stubs/package.empty.json
--port
8787
--kv-persist
--cache-persist
--do-persist
--do EXAMPLE_CLASS=DurableObjectExample
--modules
true
Usage: miniflare [script] [options]

@threepointone
Copy link
Contributor

You should file this issue under the miniflare repo

@threepointone
Copy link
Contributor

oh wait, you're saying you tried this with wrangler dev. Oh hmm. I'll have a look at this soon.

@threepointone
Copy link
Contributor

can confirm I'm seeing the same thing.
@mrbbot do you see anything obviously wrong with the way I'm passing args here? https://github.com/cloudflare/wrangler2/blob/baf38704ae8f2dc83d7dee340f841fb84aa1099e/packages/wrangler/src/dev.tsx#L250-L283

Here's an example of the args passed to it -

[
  '--experimental-vm-modules',
  '--inspect',
  '/Users/threepointone/code/testdo/node_modules/miniflare/dist/src/cli.js',
  '../../../../../../var/folders/cq/w4qlzy2d4v924d23r3yj7pk00000gn/T/tmp-26115-fSWD0vwV1mxV/server.js',
  '--watch',
  '--wrangler-config',
  '/Users/threepointone/code/testdo/node_modules/wrangler/miniflare-config-stubs/wrangler.empty.toml',
  '--env',
  '/Users/threepointone/code/testdo/node_modules/wrangler/miniflare-config-stubs/.env.empty',
  '--package',
  '/Users/threepointone/code/testdo/node_modules/wrangler/miniflare-config-stubs/package.empty.json',
  '--port',
  '8787',
  '--kv-persist',
  '--cache-persist',
  '--do-persist',
  '--do DurableClass=DurableClass',
  '--modules',
  'true'
]

@mrbbot
Copy link
Contributor

mrbbot commented Dec 29, 2021

Potentially because --do DurableClass=DurableClass is passed as a single arg and includes both a and =, both of which can be used to separate the arg name from its value. Guessing the arg parser I'm using looks for the last /= character, hence why the unexpected arg name in the error (Unexpected option: --do EXAMPLE_CLASS) is do EXAMPLE_CLASS. Guessing this doesn't happen with --binding or --kv because they don't contain =s? Could probably fix this by replacing that map with a flatMap and returning: ["--do", `${name}=${class_name}`].

@Electroid Electroid added the bug label Dec 29, 2021
@threepointone
Copy link
Contributor

Ok that's probably it, I should've separated it out. Thanks!

threepointone added a commit that referenced this issue Dec 30, 2021
When calling miniflare in `dev` the bindings are passed into the process that's spawned incorrectly; each arg needs to be a separate element in the args array to the spawn call. This PR fixes how they're added to the args array. It also enables logs on the miniflare process. (they're a bit noisy, but we can make that better separately.)

I'm personally annoyed because I can swear this was working previously, but without tests that's just my word against... my own word, lol.

fixes #172
threepointone added a commit that referenced this issue Dec 30, 2021
* pass bindings correctly to miniflare in `dev`

When calling miniflare in `dev` the bindings are passed into the process that's spawned incorrectly; each arg needs to be a separate element in the args array to the spawn call. This PR fixes how they're added to the args array. It also enables logs on the miniflare process. (they're a bit noisy, but we can make that better separately.)

I'm personally annoyed because I can swear this was working previously, but without tests that's just my word against... my own word, lol.

fixes #172

* add a changeset
@threepointone
Copy link
Contributor

This is fixed in the repo, but we have a bug where alphas aren't being published to npm on every commit right now (fix in #175). Once that lands, you can use wrangler@alpha and this issue should be resolved. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants