From 0dbfdcd722bd533e092c27d1d1b8fe13a471b389 Mon Sep 17 00:00:00 2001 From: Michael Schwobe Date: Sat, 9 Dec 2023 20:17:11 -0600 Subject: [PATCH] Fix Docker 'Cannot find package 'msw' imported from /app/build/index.js' attempt 1 --- app/entry.client.tsx | 2 +- app/entry.server.tsx | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/entry.client.tsx b/app/entry.client.tsx index 07cdbdb..3d3d630 100644 --- a/app/entry.client.tsx +++ b/app/entry.client.tsx @@ -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(); } diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 4f0e49d..8a43a85 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -10,7 +10,6 @@ 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. @@ -18,10 +17,12 @@ 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); });