DevCycleHQ / js-sdks

DevCycle - JS Based SDKs
https://docs.devcycle.com/
33 stars 6 forks source link

@devcycle/nodejs-server-sdk version 1.37.2 fails to resolve @devcycle/js-client-sdk in Remix application #991

Open rick516 opened 3 days ago

rick516 commented 3 days ago

Issue Description:

I am encountering a build error in my Remix application after installing the following dependencies:

{
  "@devcycle/nodejs-server-sdk": "1.37.2",
  "@openfeature/core": "1.4.0",
  "@openfeature/server-sdk": "1.16.2"
}

Upon running the application, the following error is thrown:

✘ [ERROR] Could not resolve "@devcycle/js-client-sdk"

    ../../node_modules/@devcycle/nodejs-server-sdk/src/clientUser.js:4:32:
      4 │ ..._1 = require("@devcycle/js-client-sdk");
        ╵                 ~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@devcycle/js-client-sdk" as
  external to exclude it from the bundle, which will
  remove this error and leave the unresolved path in
  the bundle. You can also surround this "require"
  call with a try/catch block to handle this failure
  at run-time instead of bundle-time.

9:08:38 PM [vite] error while updating dependencies:
Error: Build failed with 1 error:
../../node_modules/@devcycle/nodejs-server-sdk/src/clientUser.js:4:32: ERROR: Could not resolve "@devcycle/js-client-sdk"
    at failureErrorWithLog (/Users/user/xxx/node_modules/vite/node_modules/esbuild/lib/main.js:1472:15)
    at /Users/user/xxx/node_modules/vite/node_modules/esbuild/lib/main.js:945:25
    at /Users/user/xxx/node_modules/vite/node_modules/esbuild/lib/main.js:1353:9
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Hypothesis:

It appears that within @devcycle/nodejs-server-sdk, there is a dependency on @devcycle/js-client-sdk that is not being resolved correctly, leading to the build failure.

Specifically, in node_modules/@devcycle/nodejs-server-sdk/src/clientUser.js, the following line is present:

const js_client_sdk_1 = require("@devcycle/js-client-sdk");

This suggests that @devcycle/js-client-sdk is a required dependency but is not listed in the package.json of @devcycle/nodejs-server-sdk.

Request:

Could you please investigate this issue and provide guidance on how to resolve the dependency on @devcycle/js-client-sdk when using @devcycle/nodejs-server-sdk in a Remix application?

Thank you for your assistance.

rick516 commented 3 days ago

I have already found out why this error happens and created PR for this issue. Please check https://github.com/DevCycleHQ/js-sdks/pull/992

cdruxerman commented 2 days ago

Hi @rick516 thanks for submitting the PR, our team is taking a look right now.

rick516 commented 2 days ago

Hi, @cdruxerman I am always grateful for your DevCycle. It's indispensable for our trunk-based development.

ajwootto commented 1 day ago

Hey @rick516 , are you using the client-side bootstrapping and SSR features of the SDK?

If so, we deliberately make the JS SDK an "optional" package you have to install to use these features in order to avoid including redundant dependencies for non-SSR usecases.

If you aren't using those features and still getting this error, then it's probably an issue with how Vite is trying to bundle the SDK in your serverside bundle. The JS SDK is "optional" because it is imported using a dynamic import which is only executed when the bootstrapping functionality is used, which works as expected in a normal Node environment. The problem here is that I believe Vite is trying to bundle the SDK, and in doing so it's trying to resolve that dynamic import at build time regardless of whether it's ever called. A simple way to get around this would be to mark our SDK as an 'external' package so that Vite does not attempt to bundle it. I'm also looking at ways we might be able to tell Vite to not resolve this import statement during bundling.