Skip to content

Commit e1e5d78

Browse files
mrbbotpetebacondarwin
authored andcommittedMay 17, 2023
feature: warn when trying to use wrangler dev inside a WebContainer (#3187)
Wrangler v3 removes Miniflare 2 in favour of Miniflare 3 using `workerd`. Unfortunately, `workerd` doesn't run in the browser _(yet 😉)_, and WebContainers don't support remote mode yet. This change adds a warning when we detect `wrangler dev` running inside a WebContainer, so users know what's going on. Closes #3177

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed
 

‎.changeset/ninety-worms-beam.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
feature: add warning when trying to use `wrangler dev` inside a WebContainer

‎package-lock.json

+9-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/wrangler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"@types/supports-color": "^8.1.1",
136136
"@types/ws": "^8.5.3",
137137
"@types/yargs": "^17.0.10",
138-
"@webcontainer/env": "^1.0.1",
138+
"@webcontainer/env": "^1.1.0",
139139
"body-parser": "^1.20.0",
140140
"chalk": "^2.4.2",
141141
"cli-table3": "^0.6.3",

‎packages/wrangler/src/dev.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from "node:path";
2+
import { isWebContainer } from "@webcontainer/env";
23
import chalk from "chalk";
34
import { watch } from "chokidar";
45
import getPort from "get-port";
@@ -293,6 +294,15 @@ export function devOptions(yargs: CommonYargsArgv) {
293294
type DevArguments = StrictYargsOptionsToInterface<typeof devOptions>;
294295

295296
export async function devHandler(args: DevArguments) {
297+
if (isWebContainer()) {
298+
logger.error(
299+
`Oh no! 😟You tried to run \`wrangler dev\` in a StackBlitz WebContainer. 🤯
300+
This is currently not supported 😭, but we think that we'll get it to work soon... hang in there! 🥺`
301+
);
302+
process.exitCode = 1;
303+
return;
304+
}
305+
296306
if (!(args.local || args.experimentalLocal)) {
297307
const isLoggedIn = await loginOrRefreshIfRequired();
298308
if (!isLoggedIn) {

‎packages/wrangler/src/user/user.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ import path from "node:path";
213213
import url from "node:url";
214214
import { TextEncoder } from "node:util";
215215
import TOML from "@iarna/toml";
216-
import { HostURL } from "@webcontainer/env";
217216
import { fetch } from "undici";
218217
import {
219218
getConfigCache,
@@ -365,15 +364,7 @@ export function validateScopeKeys(
365364
return scopes.every((scope) => scope in Scopes);
366365
}
367366

368-
/**
369-
* To allow OAuth callbacks in environments such as WebContainer we need to
370-
* create a host URL which only resolves `localhost` to a WebContainer
371-
* hostname if the process is running in a WebContainer. On local this will
372-
* be a no-op and it leaves the URL unmodified.
373-
*
374-
* @see https://www.npmjs.com/package/@webcontainer/env
375-
*/
376-
const CALLBACK_URL = HostURL.parse("http://localhost:8976/oauth/callback").href;
367+
const CALLBACK_URL = "http://localhost:8976/oauth/callback";
377368

378369
let LocalState: State = {
379370
...getAuthTokens(),

0 commit comments

Comments
 (0)
Please sign in to comment.