miniflare icon indicating copy to clipboard operation
miniflare copied to clipboard

Cannot run multiple workers

Open hazcod opened this issue 4 years ago • 3 comments

Hi! Trying out miniflare beta support for multiple workers. This always errors out for my webpack scenario.

Version: 2.0.0-rc.2

Command I am running:

% npx miniflare \
	--mount api=./api --mount web=./web \
	--watch \
	--debug --verbose \
	--wrangler-env=dev --env=dev \
	--host=localhost

[mf:dbg] Initialising worker...
[mf:dbg] Options:
[mf:dbg] - Wrangler Config Path: wrangler.toml
[mf:dbg] - Wrangler Environment: dev
[mf:dbg] - Package Path: package.json
[mf:dbg] - Watch: true
[mf:dbg] - Debug: true
[mf:dbg] - Verbose: true
[mf:dbg] - Mounts: api, web
[mf:dbg] - Host: localhost
[mf:dbg] - Env Path: dev
[mf:dbg] Enabled Compatibility Flags: <none>
[mf:vrb] - beforeSetup(BuildPlugin)
[mf:vrb] - setup(CorePlugin)
[mf:vrb] - setup(HTTPPlugin)
[mf:vrb] - setup(SchedulerPlugin)
[mf:vrb] - setup(KVPlugin)
[mf:vrb] - setup(DurableObjectsPlugin)
[mf:vrb] - setup(CachePlugin)
[mf:vrb] - setup(SitesPlugin)
[mf:vrb] - setup(HTMLRewriterPlugin)
[mf:vrb] - setup(WebSocketPlugin)
[mf:vrb] - setup(BindingsPlugin)
[mf:err] Error: ENOENT: no such file or directory, open 'dev'

And without --env=dev:

% npx miniflare \
                --mount api=./api --mount web=./web \
                --watch \
                --debug --verbose \
                --wrangler-env=dev \
                --host=localhost

[mf:dbg] Initialising worker...
[mf:dbg] Options:
[mf:dbg] - Wrangler Config Path: wrangler.toml
[mf:dbg] - Wrangler Environment: dev
[mf:dbg] - Package Path: package.json
[mf:dbg] - Watch: true
[mf:dbg] - Debug: true
[mf:dbg] - Verbose: true
[mf:dbg] - Mounts: api, web
[mf:dbg] - Host: localhost
[mf:dbg] - Env Path: .env
[mf:dbg] Enabled Compatibility Flags: <none>
[mf:vrb] - beforeSetup(BuildPlugin)
[mf:vrb] - setup(CorePlugin)
[mf:vrb] - setup(HTTPPlugin)
[mf:vrb] - setup(SchedulerPlugin)
[mf:vrb] - setup(KVPlugin)
[mf:vrb] - setup(DurableObjectsPlugin)
[mf:vrb] - setup(CachePlugin)
[mf:vrb] - setup(SitesPlugin)
[mf:vrb] - setup(HTMLRewriterPlugin)
[mf:vrb] - setup(WebSocketPlugin)
[mf:vrb] - setup(BindingsPlugin)
[mf:err] MiniflareCoreError [ERR_NO_SCRIPT]: No script defined, either:
- Pass it as a positional argument, if you're using the CLI
    $ miniflare dist/worker.js
- Set the script or scriptPath option, if you're using the API
    new Miniflare({ scriptPath: "dist/worker.js" })
- Set main in package.json
    { "main": "dist/worker.js" }

    at throwNoScriptError (file:///opt/homebrew/Cellar/node/17.0.1/lib/node_modules/miniflare/node_modules/@miniflare/core/src/index.ts:202:9)
    at EventTarget.#init (file:///opt/homebrew/Cellar/node/17.0.1/lib/node_modules/miniflare/node_modules/@miniflare/core/src/index.ts:438:7)
    at EventTarget.getPlugins (file:///opt/homebrew/Cellar/node/17.0.1/lib/node_modules/miniflare/node_modules/@miniflare/core/src/index.ts:810:5)
    at createServer (file:///opt/homebrew/Cellar/node/17.0.1/lib/node_modules/miniflare/node_modules/@miniflare/http-server/src/index.ts:314:19)
    at startServer (file:///opt/homebrew/Cellar/node/17.0.1/lib/node_modules/miniflare/node_modules/@miniflare/http-server/src/index.ts:388:18)
    at main (file:///opt/homebrew/Cellar/node/17.0.1/lib/node_modules/miniflare/src/cli.ts:89:5)

Example configuration in web/wrangler.toml:

name = "foo"
type = "webpack"

workers_dev = false
usage_model = 'bundled'
compatibility_flags = []
compatibility_date  = "2021-09-20"

[env.dev.vars]
ENVIRONMENT = "dev" 
[env.dev]
webpack_config = "webpack.config.dev.js"

[env.prd.vars]
ENVIRONMENT = "dev" 
[env.prd]
routes      = ['foo.bar/*']
zone_id     = ''
account_id  = ''
webpack_config = "webpack.config.prd.js"

[build]
watch_dir = "src/"
[build.upload]
format = "service-worker"

[env.dev.build]
command     = "npm install && hugo --gc --minify --config=config.dev.yml && npm run build-dev"
watch_dir   = "src/"
[env.dev.build.upload]
format = "service-worker"

[env.prd.build]
command     = "npm install && hugo --gc --minify --config=config.prd.yml && npm run build-prd"
watch_dir   = "src/"
[env.prd.build.upload]
format = "service-worker"

[site]
bucket      = "./generated/"
entry-point = "./src/"

hazcod avatar Nov 24 '21 09:11 hazcod

+1

10thfloor avatar Nov 26 '21 22:11 10thfloor

Hey both! 👋 Do you have any script in the directory you're running Miniflare in, or are you just trying to load the two mounts? Miniflare currently requires a script for the parent worker, but thinking about it, this probably doesn't make sense with mounts.

@hazcod, the --env is confusingly for setting the path to a .env file, not the Wrangler enviornment. --wrangler-env is the right flag for that, though currently there's no way to customise which Wrangler environment to load in mounted workers. I'm working on that. 👍

mrbbot avatar Nov 30 '21 12:11 mrbbot

Hey! 👋 [email protected] has just been released, that might fix this issue. Would you be able to try it out?

mrbbot avatar Dec 08 '21 23:12 mrbbot

Hey! 👋 I know it's been a while, but just checking, was this issue resolved eventually?

mrbbot avatar Oct 17 '22 16:10 mrbbot

Hey! Thanks for raising this issue! I'm going to close it for now since we haven't heard from you in a while, but if there's still outstanding questions feel free to comment with a minimal reproduction and we can open it again and investigate further.

penalosa avatar Jan 09 '23 16:01 penalosa