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
- fix: need to patch remix serve due to sourcemap bug https://github.com/remix-run/remix/issues/8309#issuecomment-1868402299 — committed to LumeWeb/web3.news by pcfreak30 6 months ago
- build(frontend): downgrade remix to `v2.3.1`. Because of https://github.com/remix-run/remix/issues/8309. — committed to IgnisDa/ryot by IgnisDa 6 months ago
- Downgrade remix version (#530) * build(frontend): downgrade remix to `v2.3.1`. Because of https://github.com/remix-run/remix/issues/8309. * ci(frontend): downgrade remix version * build(back... — committed to IgnisDa/ryot by IgnisDa 6 months ago
- Downgrade Remix because of sourcemap bug See https://github.com/remix-run/remix/issues/8309 — committed to AutomatedProcessImprovement/pix-portal by iharsuvorau 6 months ago
- Downgrade @remix-run/serve to 2.3.1 When trying to access the Zod errors, it somehow trips the installed sourcemapping which fails and throws an error because Zod doesn't ship with source maps. This ... — committed to CtrlZvi/zyf by CtrlZvi 6 months ago
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.patchThanks @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.
Not sure what’s the difference, but that patch didn’t quite work for me. This one did:
and in your
package.json: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?
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.jsto see if it has the comment at the end?If not, I’m not sure why
source-map-supportis trying to load the sourcemap then. Do we need to add afs.existsSync()check afterurl.fileURLToPath()?@brophdawg11 we may need to re-open this.
Hello @kiliman , is it known why the
remix-serveexpects 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
--sourcemapargument to the build command.Just note that sourcemaps contain the entire source, so client sourcemaps will contain server code as well.
The default one provided in the vite template.
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:
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: