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

fix: workaround for importing SDKs in pnpm monorepos #2

Closed
wants to merge 1 commit into from

Conversation

disintegrator
Copy link

There's an odd interaction between pnpm/yarn monorepos and the rules next.js uses to transpile packages. The bundler under the hood should avoid certain transpilation for node_modules but I suspect that since the SDK is symlinked and the real location isn't in node_modules then it's not being treated as "vendor" code. You can sort of confirm this behavior by looking in apps/sdk-tester/.next/server/app/page.js and searching for the string packages/client-subscriptions/lib/config.js. That code shouldn't be in that bundle... Compare this with npm modules in apps/sdk-tester/.next/server/vendor-chunks which is where I would expect the SDK to end up.

My hunch is that if you were to publish the SDK to npm and install it like any other third-party package then it'll work as intended. I'll need to test this out on my end too. There might also be a way to tell Next.js to treat certain monorepos dependencies as "vendor" code.

Until then, this PR contains a quick fix that might unblock you. In my testing, the web app loaded into an error state where it was retrying several API requests and getting a 401 because I don't have API credentials on my end. This does tell me that the code is loading and running though.

I'll need to keep digging and possibly file an issue with the Next.js team.

You may need to delete .next cache folder before running the dev server.

Here's a couple of existing issues:

vercel/next.js#35412
vercel/next.js#35110

@disintegrator disintegrator changed the title fix: allow importing SDKs in pnpm monorepos fix: workaround for importing SDKs in pnpm monorepos Feb 16, 2024
@disintegrator disintegrator deleted the patch-1 branch February 27, 2024 20:44
@disintegrator
Copy link
Author

This is no longer needed. We shipped an update that removes the "type" field. If you update your CLI and generate again then you'll get the same change as in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant