miniflare
miniflare copied to clipboard
Using --env with --mount ignores filename
I created a repo with the minimum setup to reproduce.
When using --mount
in sub-directories and --env
the filename passed in is ignored.
Working
If the filename is the default .env
miniflare --env ./route-b/.env \
--mount a=./route-a \
--mount b=./route-b \
--watch \
--debug \
-p 3000
The variables in route-b/.env
are correctly bound.
Not Working
If the filename is not the default .env.test
miniflare --env ./route-a/.env.test \
--mount a=./route-a \
--mount b=./route-b \
--watch \
--debug \
-p 3000
What I expect
The variables in route-a/.env.test
should be bound.
What actually happens
The variables are not bound, and I get this error:
ReferenceError: MY_KEY_A is not defined
at /path/to/repro-miniflare-issue-001/route-a/worker/index.js:4:3
at /path/to/repro-miniflare-issue-001/node_modules/@miniflare/shared/src/event.ts:29:9
at EventTarget.<anonymous> (/path/to/repro-miniflare-issue-001/node_modules/@miniflare/shared/src/event.ts:77:9)
at EventTarget.[nodejs.internal.kHybridDispatch] (node:internal/event_target:562:20)
at EventTarget.dispatchEvent (node:internal/event_target:504:26)
at EventTarget.dispatchEvent (/path/to/repro-miniflare-issue-001/node_modules/@miniflare/shared/src/event.ts:63:18)
at EventTarget.dispatchEvent (/path/to/repro-miniflare-issue-001/node_modules/@miniflare/shared/src/event.ts:87:26)
at EventTarget.[kDispatchFetch] (/path/to/repro-miniflare-issue-001/node_modules/@miniflare/core/src/standards/event.ts:356:13)
at EventTarget.[kDispatchFetch] (/path/to/repro-miniflare-issue-001/node_modules/@miniflare/core/src/index.ts:1067:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Hey! 👋 --env
only applies to the parent worker. All mounted worker configuration must be derivable from package.json
, .env
and wrangler.toml
files inside the mounted directory. No configuration from the parent worker (aside from the watch
and storage persistence options) is copied to mounted workers. This is an intentional design decision, allowing each mounted worker to have its own separate bindings. You can set a custom --wrangler-env
for each mount using an @
:
miniflare --mount a=./route-a@test
# ./route-a/wrangler.toml
# ...
[env.test.vars]
KEY = "value"
Would you be open to a pull request describing that a bit more in the docs?
Of course! 🙂
Hey! 👋 We haven't heard from you for a while, so I'm going to close this issue. It's unlikely we'll have time to fix this in Miniflare 2. Our development effort is primarily focused on version 3. Miniflare 3 no longer uses mounts
, instead preferring an array of workers
. 👍