Skip to content

Commit

Permalink
fix: resolve non-js modules correctly in local mode
Browse files Browse the repository at this point in the history
In #633, we missed passing a cwd to the process that runs the miniflare cli. This broke how miniflare resolves modules, and led back to the dreaded "path should be a `path.relative()`d string" error. The fix is to simply pass the cwd to the `spawn` call.
  • Loading branch information
threepointone committed Mar 23, 2022
1 parent ef0aaad commit 961f620
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changeset/gold-forks-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: resolve non-js modules correctly in local mode

In https://github.com/cloudflare/wrangler2/pull/633, we missed passing a cwd to the process that runs the miniflare cli. This broke how miniflare resolves modules, and led back to the dreaded "path should be a `path.relative()`d string" error. The fix is to simply pass the cwd to the `spawn` call.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
packages/wrangler/vendor/
packages/wrangler/wrangler-dist/
packages/wrangler/miniflare-dist/
packages/example-worker-app/dist/
packages/example-remix-pages-app/build
packages/example-remix-pages-app/public/
Expand Down
22 changes: 14 additions & 8 deletions packages/wrangler/src/dev/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,20 @@ function useLocalWorker({
const optionsArg = JSON.stringify(options, null);

console.log("⎔ Starting a local server...");
local.current = spawn("node", [
"--experimental-vm-modules", // ensures that Miniflare can run ESM Workers
"--no-warnings", // hide annoying Node warnings
"--inspect", // start Miniflare listening for a debugger to attach
miniflareCLIPath,
optionsArg,
// "--log=VERBOSE", // uncomment this to Miniflare to log "everything"!
]);
local.current = spawn(
"node",
[
"--experimental-vm-modules", // ensures that Miniflare can run ESM Workers
"--no-warnings", // hide annoying Node warnings
"--inspect", // start Miniflare listening for a debugger to attach
miniflareCLIPath,
optionsArg,
// "--log=VERBOSE", // uncomment this to Miniflare to log "everything"!
],
{
cwd: path.dirname(scriptPath),
}
);

local.current.on("close", (code) => {
if (code) {
Expand Down

0 comments on commit 961f620

Please sign in to comment.