-
Notifications
You must be signed in to change notification settings - Fork 48
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
Webpack unable to load binary "sdk-napi.win32-x64-msvc.node" when using "@bitwarden/sdk-napi" in a NextJS 13 App Dir API route ( Edge runtime & Node.js runtimes ) #112
Comments
Hi @jules-sommer, The Napi SDK (Node-API) is only compatible with node.js. By default Webpack attempts to bundle external dependencies, I'm not well versed with how next.js works, but I've previously used vercel/next.js#17807 suggests using |
Oh, nice - thank you; that's a fairly clean solution to avoid having webpack bundle it leaving me dependent on the NPM module alone - still will be interesting to see if it runs well in a NextJs API route, but without that bundling I see no reason why it wouldn't run as API routes are NodeJs runtime by default. I will play around with that and get back to you, thanks for the quick response! |
I managed to get to this point with I am going to be away from my PC but I will do that fiddling later today and update this issue in case anyone else has the same use case and wants to get the SDK running, it's possible my environment variable was incorrectly set. |
{
data: null,
errorMessage: 'Internal error: Failed to parse IdentityTokenResponse',
success: false
} I am now getting this error with a valid access token ( triple-checked ) and the error throws at client.loginWithAccessToken funtion. Any thoughts? |
That typically means the response from the bitwarden server is malformed, it could be due to quite a few reasons. We recently merged a change in #109 that improves the error message for this and it will be included in the next release. In the meanwhile I believe you should be able to download the latest CLI build from the |
@jules-sommer Version 0.3.0 which just got released to npm should provide better error handling for the IdentityTokenResponse error. |
Hey, thanks for keeping me updated, below is the stack trace that I am getting when I hit my API route. I think the I tried a few other methods of getting webpack to load the .node binary and or ignore it to no avail. Very frustrating. Anyways this is the error after doing a pnpm update on your SDK to 0.3.0.
|
That definitely sounds like a bug on our end. I believe it's caused by our NAPI integration initializing the logger multiple times. Could you try creating a single instance of the I'll break out a new issue for this. |
Thanks so much for helping me out with this, I appreciate it - and yes, I suppose the way my code is written currently, a new instance of the client is created every time the API is hit, I hadn't thought of that being an issue. Come to think of it though, I already solve this problem elsewhere in my codebase for the database, I just have a utility function check if an instance has been initialized and if not create one otherwise return the existing so I don't have thousands of open connections to my DB in prod. I will try to apply that same logic to the BW client and see what happens! |
So with a global client instance this is the error I am getting now, it seems to have changed the behaviour slightly in the direction of functionality but I've not quite got it yet. It looks like that was the issue with the logger though, so something to look into for sure, I can post the code I used but basically I just conditionally initialized a global instance of the BW client if one had not already been created and exported it to be consumed by the API route.
|
The last error message indicates that the command is missing an argument. Can you try updating your code with: const secrets = await client.secrets().list("org-id"); |
Okay, I didn't catch that in the docs, but for the life of me I can't figure out what organization id you're referring to - again, searching through the docs I only see an OID referenced for SSO, but nothing with regards to this SDK or the secrets manager in general, this is totally just my ignorance in using this SDK and is probably why I can't authenticate; but I've searched around my API keys and such in the BW web vault dashboard, as well as the docs, for about an hour and couldn't find the specific token you're referencing. When I setup the SDK the only .env variable I set was my access token. I've been working on another project so haven't had a minute to check in here, hence my late reply, so sorry about that as well, and forgive my ignorance and lack of familiarity with your SDK. Hopefully this is all that's preventing my code from running and I will be sorted once I find this other identifier I am after. |
We haven't yet properly documented the node api unfortunately. The organization id is visible in the url. When going to the secrets manager dashboard you have a url like |
I would love to help with that if you're allowing open-source contributors, given I now have some experience, but thank you, I will try it and update the issue if that finally gets me going with the SDK!! |
Hey @jules-sommer, I'm closing this issue since I believe we resolved the root cause of your issues. Hopefully the secret manager team can get some documentation published soon. Feel free to reach out to support in case you run into any other issues. |
Steps To Reproduce
npx create-next-app@latest
pnpm add @bitwarden/sdk-napi
, this should also install the package-lock.json deps.http://localhost:3000/api/bitwarden
with a GET requestpnpm run dev
( or npm / yarn, etc depending on your local environment )http://localhost:3000/api/bitwarden
thus sending the GET request to the server we've just created to be greeted by the error I am receiving on my local reproduction which pasted below:Expected Result
So obviously the secrets manager is in beta and I was excited to test it out in a production environment, in this case a NextJs 13 web app, I wanted to created an API route ( which would obviously be behind authentication in production, however is not in this reproduction for brevity ) that would return a JSON serialized list of the secrets in my BW Secrets Manager project.
Curious to hear what you have to say about this, I am aware I might be using the SDK out of its intended environment, though NextJS api routes are NodeJS runtime and I would expect this to work, though obviously my webpack bundler is having some trouble with the SDK module.
Thanks for taking the time, and I appreciate any feedback!
Actual Result
Again, I am getting this build error when pulling that SDK into my NextJS application.
Screenshots or Videos
Additional Context
No response
Operating System
Windows
Operating System Version
No response
Build Version
@bitwarden/[email protected]
Issue Tracking Info
The text was updated successfully, but these errors were encountered: