Skip to content

Commit

Permalink
Fix Docker 'Cannot find package 'msw' imported from /app/build/index.…
Browse files Browse the repository at this point in the history
…js' attempt 1
  • Loading branch information
michaelschwobe committed Dec 10, 2023
1 parent 609e18c commit 0dbfdcd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/entry.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";

async function prepareApp() {
if (ENV.MOCKS) {
if (process.env.NODE_ENV !== "production" && process.env.MOCKS === "true") {
const { worker } = await import("../tests/mocks/browser");
return worker.start();
}
Expand Down
7 changes: 4 additions & 3 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { PassThrough } from "node:stream";
import { renderToPipeableStream } from "react-dom/server";
import { server } from "../tests/mocks/node";
import { getEnv, init } from "./utils/env.server";

// Initialize typesafe environment variables and global ENV object.
init();
global.ENV = getEnv();

// Enable API mocking.
if (ENV.MOCKS) {
if (process.env.NODE_ENV !== "production" && process.env.MOCKS === "true") {
const { server } = await import("../tests/mocks/node");
server.listen();
console.info("[MSW] Mocking enabled.");
if (ENV.MODE === "development") {
if (process.env.NODE_ENV === "development") {
// Only log mocked requests in development mode.
server.events.on("request:start", ({ request }) => {
console.info(request.method, "[MSW]", request.url);
});
Expand Down

0 comments on commit 0dbfdcd

Please sign in to comment.