remix: Error related to sourcemaps in production build

Reproduction

Using a unstable vite template and building and deploying it gives an error about a sourcemap file missing.

All remix packages are at v2.4.0.

Here is the part of the dockerfile that copies relevant files.

System Info

System:
    OS: Linux 6.6 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 19.07 GB / 27.26 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 20.5.1 - ~/.proto/bin/node
    Yarn: 4.0.0 - ~/.proto/bin/yarn
    npm: 10.2.1 - /usr/sbin/npm
    bun: 1.0.7 - ~/.proto/bin/bun

Used Package Manager

yarn

Expected Behavior

The production server to work fine.

Actual Behavior

Here is the stderr for the server:

Error: ENOENT: no such file or directory, open '/home/ryot/build/server/index.js.map'
    at readFileSyncUtf8 (node:internal/fs/read/utf8:20:3)
    at Object.readFileSync (node:fs:467:12)
    at Array.retrieveSourceMap (/home/ryot/node_modules/@remix-run/serve/dist/cli.js:49:37)
    at /home/ryot/node_modules/source-map-support/source-map-support.js:85:24
    at mapSourcePosition (/home/ryot/node_modules/source-map-support/source-map-support.js:216:21)
    at wrapCallSite (/home/ryot/node_modules/source-map-support/source-map-support.js:397:20)
    at Function.prepareStackTrace (/home/ryot/node_modules/source-map-support/source-map-support.js:446:39)
    at maybeOverridePrepareStackTrace (node:internal/errors:140:29)
    at prepareStackTrace (node:internal/errors:114:5)
    at getStackString (node:internal/util/inspect:1239:16)

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 16
  • Comments: 52 (14 by maintainers)

Commits related to this issue

Most upvoted comments

I got the same problem when trying to throw zod error into the catch block, but it wasn’t thrown, instead the remix-serve yelling that the can’t find zod’s source map, I did try build in production mode but still get the same error thrown, except no stack strace, why do we even include the source map support in production tho? And at the end, my temporary solution is to comment out the source map support install part from the remix-serve package in node modules, and it works as normal

Here’s a patch while I work on the PR

patches/@remix-run+serve+2.4.1.patch

diff --git a/node_modules/@remix-run/serve/dist/cli.js b/node_modules/@remix-run/serve/dist/cli.js
index fa63111..6647eea 100755
--- a/node_modules/@remix-run/serve/dist/cli.js
+++ b/node_modules/@remix-run/serve/dist/cli.js
@@ -41,13 +41,15 @@ var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
 process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
 sourceMapSupport__default["default"].install({
   retrieveSourceMap: function (source) {
-    // get source file with the `file://` prefix
-    let match = source.match(/^file:\/\/(.*)$/);
-    if (match) {
-      let filePath = url__default["default"].fileURLToPath(source);
+    let filePath = source;
+    if (filePath.startsWith("file://")) {
+      filePath = url__default["default"].fileURLToPath(source);
+    }
+    let mapPath = `${filePath}.map`;
+    if (fs__default["default"].existsSync(mapPath)) {
       return {
         url: source,
-        map: fs__default["default"].readFileSync(`${filePath}.map`, "utf8")
+        map: fs__default["default"].readFileSync(mapPath, "utf8")
       };
     }
     return null;

Thanks @VHall1! This should be resolved by #8446 and available in the next release.

I am running 2.4.1, base remix server, no vite, and I am getting a very similar error, only related to zod, though.

Screenshot 2024-01-06 at 9 32 25 PM

Not sure what’s the difference, but that patch didn’t quite work for me. This one did:

diff --git a/dist/cli.js b/dist/cli.js
index fa631116d949ac08887e5a6e7a0a62c5107e77a3..6647eea016df7334db87e973ea1e6bfb933b744c 100644
--- a/dist/cli.js
+++ b/dist/cli.js
@@ -41,13 +41,15 @@ var getPort__default = /*#__PURE__*/_interopDefaultLegacy(getPort);
 process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
 sourceMapSupport__default["default"].install({
   retrieveSourceMap: function (source) {
-    // get source file with the `file://` prefix
-    let match = source.match(/^file:\/\/(.*)$/);
-    if (match) {
-      let filePath = url__default["default"].fileURLToPath(source);
+    let filePath = source;
+    if (filePath.startsWith("file://")) {
+      filePath = url__default["default"].fileURLToPath(source);
+    }
+    let mapPath = `${filePath}.map`;
+    if (fs__default["default"].existsSync(mapPath)) {
       return {
         url: source,
-        map: fs__default["default"].readFileSync(`${filePath}.map`, "utf8")
+        map: fs__default["default"].readFileSync(mapPath, "utf8")
       };
     }
     return null;

and in your package.json:

"@remix-run/serve@2.4.1": "patches/@remix-run__serve@2.4.1.patch"

Ok, I was able to reproduce it. Re-opening this issue.

Gave this another shot. I believe this update should resolve both of the issues raised above (3rd party packages and source maps not available).

Experienced the same with postgres.js ✌️ Solved the issue by downgrading to 2.3.1.

The most straight-forward solution right now is to stay on 2.3.1 or apply one of the patches recommended above.

Any updates here. I’m getting this error. Is this the same bug?

Error: ENOENT: no such file or directory, open '/app/node_modules/.pnpm/axios@1.6.0/node_modules/axios/lib/adapters/http.js.map'
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at Object.openSync (node:fs:596:3)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at Object.readFileSync (node:fs:464:35)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at Array.retrieveSourceMap (/app/node_modules/.pnpm/@remix-run+serve@2.4.1_typescript@5.2.2/node_modules/@remix-run/serve/dist/cli.js:50:37)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at /app/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:85:24
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at mapSourcePosition (/app/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:216:21)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at wrapCallSite (/app/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:397:20)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at Function.prepareStackTrace (/app/node_modules/.pnpm/source-map-support@0.5.21/node_modules/source-map-support/source-map-support.js:446:39)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at maybeOverridePrepareStackTrace (node:internal/errors:140:29)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at prepareStackTrace (node:internal/errors:114:5)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at parseStackFrames (/app/node_modules/.pnpm/@sentry+utils@7.70.0/node_modules/@sentry/src/eventbuilder.ts:22:1)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at exceptionFromError (/app/node_modules/.pnpm/@sentry+utils@7.70.0/node_modules/@sentry/src/eventbuilder.ts:34:1)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at Object.eventFromUnknownInput (/app/node_modules/.pnpm/@sentry+utils@7.70.0/node_modules/@sentry/src/eventbuilder.ts:103:1)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at NodeClient.eventFromException (/app/node_modules/.pnpm/@sentry+core@7.70.0/node_modules/@sentry/src/server-runtime-client.ts:52:1)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at NodeClient.captureException (/app/node_modules/.pnpm/@sentry+core@7.70.0/node_modules/@sentry/src/baseclient.ts:157:1)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at NodeClient.captureException (/app/node_modules/.pnpm/@sentry+core@7.70.0/node_modules/@sentry/src/server-runtime-client.ts:87:1)
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging at /app/node_modules/.pnpm/@sentry+core@7.70.0/node_modules/@sentry/src/hub.ts:200:1 {
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging errno: -2,
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging syscall: 'open',
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging code: 'ENOENT',
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging path: '/app/node_modules/.pnpm/axios@1.6.0/node_modules/axios/lib/adapters/http.js.map'
2024-01-03 11:10:33.565 [fly_io] [INFO] ewr windmill-staging }

FYI Upgrading to v2.4.1 did not fix the issue.

@IgnisDa Hmm… then I’m not sure why it’s trying to access sourcemaps if you’re not generating them. Can you check build/index.js to see if it has the comment at the end?

//# sourceMappingURL=index.js.map

If not, I’m not sure why source-map-support is trying to load the sourcemap then. Do we need to add a fs.existsSync() check after url.fileURLToPath()?

@brophdawg11 we may need to re-open this.

By default, Vite doesn’t generate sourcemaps for production builds. You will need to pass the --sourcemap argument to the build command.

Just note that sourcemaps contain the entire source, so client sourcemaps will contain server code as well.

Hello @kiliman , is it known why the remix-serve expects to find this sourcemap file in the first place? I imagine we would not want to build and deploy the app with sourcemaps in the build output as well.

By default, Vite doesn’t generate sourcemaps for production builds. You will need to pass the --sourcemap argument to the build command.

Just note that sourcemaps contain the entire source, so client sourcemaps will contain server code as well.

Are you using Remix App Server or Express?

The default one provided in the vite template.

Does the map file actually exist at the paths logged?

It does not.

I would also like to add that the build is happening inside a docker container (node:20.5.1-bookworm-slim).

Here are the contents after build:

image

Can confirm, I’m having the same issue on Windows 11.

As far as I can tell, it seems like this is related to the 2.4.0 release. Pegged all remix packages locally to version 2.3.1 and that seems to have “solved” the issue.

Think the issue might be related to this new feature: https://github.com/remix-run/remix/pull/8174

Stack trace for reference:

Error: ENOENT: no such file or directory, open 'C:\C:\Users\Frk\onx\onx-mod\apps\website\build\index.js.map'
    at Object.readFileUtf8 (node:internal/fs/sync:25:18)
    at Object.readFileSync (node:fs:441:19)
    at Array.retrieveSourceMap (C:\Users\Frk\onx\onx-mod\node_modules\@remix-run\serve\dist\cli.js:49:37)
    at C:\Users\Frk\onx\onx-mod\node_modules\source-map-support\source-map-support.js:85:24
    at mapSourcePosition (C:\Users\Frk\onx\onx-mod\node_modules\source-map-support\source-map-support.js:216:21)
    at wrapCallSite (C:\Users\Frk\onx\onx-mod\node_modules\source-map-support\source-map-support.js:397:20)
    at Function.prepareStackTrace (C:\Users\Frk\onx\onx-mod\node_modules\source-map-support\source-map-support.js:446:39)
    at maybeOverridePrepareStackTrace (node:internal/errors:141:29)
    at prepareStackTrace (node:internal/errors:115:5)
    at process.emit (C:\Users\Frk\onx\onx-mod\node_modules\source-map-support\source-map-support.js:508:52) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\C:\\Users\\Frk\\onx\\onx-mod\\apps\\website\\build\\index.js.map'
}