Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error related to sourcemaps in production build #8309

Closed
IgnisDa opened this issue Dec 16, 2023 · 52 comments · Fixed by #8321 or #8446
Closed

Error related to sourcemaps in production build #8309

IgnisDa opened this issue Dec 16, 2023 · 52 comments · Fixed by #8321 or #8446

Comments

@IgnisDa
Copy link

IgnisDa commented Dec 16, 2023

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)
@VHall1
Copy link
Contributor

VHall1 commented Dec 17, 2023

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: #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'
}

@IgnisDa
Copy link
Author

IgnisDa commented Dec 17, 2023

@VHall1 Does this problem happen for you in docker or normal builds?

@VHall1
Copy link
Contributor

VHall1 commented Dec 17, 2023

Normal builds. Got a repo to reproduce the issue going in here: https://github.com/VHall1/dummy-remix-app. Thrown an error inside of the index route and got the same issue

image

@IgnisDa
Copy link
Author

IgnisDa commented Dec 18, 2023

THanks for the repro!

@kiliman
Copy link
Collaborator

kiliman commented Dec 18, 2023

I'll take a look. Thanks for the report.

@VHall1
Copy link
Contributor

VHall1 commented Dec 18, 2023

Just tested on mac and that seems to load the sourcemap correctly, so this is looking like a platform issue

@VHall1
Copy link
Contributor

VHall1 commented Dec 18, 2023

Took a stab at submitting a PR to fix this issue. Would appreciate another pair of eyes to review it and make sure everything makes sense as this is my first contribution to the project.

@brophdawg11
Copy link
Contributor

This is resolved by #8321 and will be included in the next release 👍

@adaboese
Copy link

Confirming that pegging to v2.3.1 fixes the issue. Thank you

Copy link
Contributor

🤖 Hello there,

We just published version 2.4.1-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@IgnisDa
Copy link
Author

IgnisDa commented Dec 21, 2023

@Hey @brophdawg11, I tried this wil 2.4.1-pre.2, but I get the same error.

@kiliman
Copy link
Collaborator

kiliman commented Dec 22, 2023

Are you using Remix App Server or Express?

Can you log the source and filePath in the retrieveSourceMap handler?

https://github.com/remix-run/remix/pull/8321/files?diff=unified&w=1

It looks like this fix works for macOS and Windows, but perhaps Linux is different. Does the map file actually exist at the paths logged?

@IgnisDa
Copy link
Author

IgnisDa commented Dec 22, 2023

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

@kiliman
Copy link
Collaborator

kiliman commented Dec 22, 2023

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.

@fobos531
Copy link

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.

@IgnisDa
Copy link
Author

IgnisDa commented Dec 22, 2023

Yep, as mentioned above, I do not want to generate the final build with sourcemaps (or anything useless for that matter).

Copy link
Contributor

🤖 Hello there,

We just published version 2.4.1 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 removed the awaiting release This issue has been fixed and will be released soon label Dec 22, 2023
@kiliman
Copy link
Collaborator

kiliman commented Dec 22, 2023

@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.

@fobos531
Copy link

@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.

Hello @kiliman

Just checked on my end - to give more context, this is a Vite build. I do NOT have this in the generated build/server/index.js. So it definitely looks like some part of code is trying to load the sourcemap while it doesn't at all exist.

@adaboese
Copy link

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

@kiliman
Copy link
Collaborator

kiliman commented Dec 22, 2023

Is this only happening in Docker? Linux?

I cannot reproduce this using Vite Dev Server or Custom Express server on macOS.

I'm on Remix v2.4.1.

@kiliman
Copy link
Collaborator

kiliman commented Dec 22, 2023

Also, does the error occur on startup, and your app won't run? Or do you get the sourcemap error when an exception is thrown?

IgnisDa added a commit to IgnisDa/ryot that referenced this issue Dec 31, 2023
IgnisDa added a commit to IgnisDa/ryot that referenced this issue Dec 31, 2023
* build(frontend): downgrade remix to `v2.3.1`.

Because of remix-run/remix#8309.

* ci(frontend): downgrade remix version

* build(backend): bump version
@swalker326
Copy link

Just to add some more discussion/a pnpm solution

I've fixed it by applying a patch to remix.

pnpm patch @remix-run/serve

it will prompt you with a file to edit, here is the new content (if on mac you can cmd +click it to open it in vscode)

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);
      //   return {
      //     url: source,
      //     map: fs__default["default"].readFileSync(`${filePath}.map`, "utf8")
      //   };
    }
    return null;
  }
});

I just commented out the return so it always is returning null on sourceMap

In the same terminal where you ran patch it should give you a command to run to apply the patch. Something like this:
pnpm patch-commit /private/var/folders/q7/qmr04v0566bbsq7g4fzhr6tr0000gn/T/38893e41339ff1ba3643d6010ef1f544

You also have to update your docker file to copy over your patches directory at build time so pnpm install will apply them.

# Install node modules
COPY --link patches patches/

Such is life in unstable land.

@Mxs2019
Copy link

Mxs2019 commented Jan 3, 2024

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 }

@IgnisDa
Copy link
Author

IgnisDa commented Jan 3, 2024

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

@VHall1
Copy link
Contributor

VHall1 commented Jan 4, 2024

Looking at this again, and wondering if one of the issues only happens when errors are thrown by external packages, rather than the components themselves. Seems like source-map-support might be passing the dependency URL in the source as part of the stack trace, and because we don't have sourcemaps available for those dependencies it fails. Maybe a strawman would be to fallback to the unfriendly path if no sourcemaps are available?

edit: catching up on this now. Seems like a patch has been provided already. Tried locally and can confirm it works with node packages

iharsuvorau added a commit to AutomatedProcessImprovement/pix-portal that referenced this issue Jan 5, 2024
CtrlZvi added a commit to CtrlZvi/zyf that referenced this issue Jan 6, 2024
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 bug (or at least a very similar one) is being
tracked in remix-run/remix#8309, but until it
is resolved, I'm pinning the version of the Remix server to 2.3.1 since
that is the latest version that is not affected.
@dwcarr
Copy link

dwcarr commented Jan 7, 2024

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

@ledgerfetcher
Copy link

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

@dwcarr
Copy link

dwcarr commented Jan 7, 2024

Yes, I can confirm that downgrading to 2.3.1 fixes the issue.

@VHall1
Copy link
Contributor

VHall1 commented Jan 7, 2024

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

@brophdawg11
Copy link
Contributor

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

@brophdawg11 brophdawg11 added the awaiting release This issue has been fixed and will be released soon label Jan 9, 2024
Copy link
Contributor

github-actions bot commented Jan 9, 2024

🤖 Hello there,

We just published version 2.5.0-pre.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@IgnisDa
Copy link
Author

IgnisDa commented Jan 9, 2024

It works with the above pre-release. Thanks @VHall1!

@VHall1
Copy link
Contributor

VHall1 commented Jan 9, 2024

that is great! Thanks for confirming 😄

@IgnisDa
Copy link
Author

IgnisDa commented Jan 11, 2024

Hey @VHall1, when will v2.5.0 be released?

Copy link
Contributor

🤖 Hello there,

We just published version 2.5.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@brophdawg11 brophdawg11 removed the awaiting release This issue has been fixed and will be released soon label Jan 19, 2024
@erlangparasu
Copy link

any updates?

@IgnisDa
Copy link
Author

IgnisDa commented Mar 19, 2024

@erlangparasu This has long since been fixed with 2.5.0. I recommend you upgrade to that version and if the issue still persists, create a new issue.

@erlangparasu
Copy link

@erlangparasu This has long since been fixed with 2.5.0. I recommend you upgrade to that version and if the issue still persists, create a new issue.

thanks 2.5.0 works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment