yarbsemaj / sveltekit-adapter-lambda

An adapter to build a SvelteKit app into a lambda ready for deployment with lambda proxy via the Serverless Framework or CDK.
https://www.npmjs.com/package/@yarbsemaj/adapter-lambda
MIT License
77 stars 16 forks source link

Dependency incompatibility with Sentry - No loader is configured for ".node" files #40

Closed plourenco closed 2 months ago

plourenco commented 3 months ago

Hi,

It seems there's a dependency incompatibility when using the adapter with sentry (@sentry/sveltekit). If you install sentry packages while using the adapter, the following error will occur when building:

> Using adapter-serverless
✘ [ERROR] No loader is configured for ".node" files: node_modules/fsevents/fsevents.node

    node_modules/fsevents/fsevents.js:13:23:
      13 │ const Native = require("./fsevents.node");

To reproduce the problem the package @sentry/sveltekit needs to be installed and imported in hooks.server.ts.

import * as Sentry from '@sentry/sveltekit';

export const handle = Sentry.sentryHandle();
yarbsemaj commented 3 months ago

Hi @plourenco thank you for your interest in my project.

This looks to be a problem when using vite with esbuild, would you mind trying this solution and reporting back?

https://stackoverflow.com/a/75655669

Thanks James

plourenco commented 2 months ago

Hi James, Unfortunately, that didn't seem to do the trick, I suspect that might not be the cause. I'll set up a sandbox with a reproducible example in case it helps narrow down the problematic dependency. Thanks!

yarbsemaj commented 2 months ago

Hi @plourenco Thanks for trying that, a sandbox project would really help. The server bundle is quite simple with minimal external dependencies. The only thing really added is svelte’s own node polyfills (and a library that handles some of the cookie stuff)

plourenco commented 2 months ago

Hi @yarbsemaj Yes, that makes sense, it's quite odd. Here's an empty sveltekit project with @yarbsemaj/adapter-lambda and @sentry/sveltekit. The issue should arrise at the end of the build step (npm run build), however, building succeeds if both lines of hooks.server.ts (sentry import and handle) are commented out (client side sentry still works).

yarbsemaj commented 2 months ago

Thanks @plourenco i’m not sure I’ll have time to look at this in the next week unfortunately as I’m away from my desk, but I will when I get back :)

yarbsemaj commented 2 months ago

Hi @plourenco I was unable to recreate the issue you were seeing, in fact it built and deployed fine and is running on https://d3airuk00m0jmc.cloudfront.net/ if you wish to check it out. I had to install @babel/preset-typescript as it complained without it for some reason.

I know "it works on my machine" is a bit of an unsatisfactory outcome so i've raised a PR with a docker file in it that when built and run with the commands in the readme will build and deploy your application.

It may look like nothing is happening for a while, but i think that's an issue with serverless running inside docker, I think adding --verbose to the end of the CDM line in the Dockerfile and rebuilding the image it should give you more feedback.

Thanks James

plourenco commented 2 months ago

Hello @yarbsemaj,

Thank you for your efforts in troubleshooting this, that's for sure more than satisfactory 👍 It seems that even while running with docker, I got the same fsevents loader error log. I've tried running with node18, building for amd64 (I'm using arm64) but no luck yet.

Nevertheless, given that you were not able to reproduce it and deployment is running just fine, I'm closing this issue for now until I can better narrow down the cause. If I have more information, I'll add a few comments or re-open it.

Thanks once again.