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

C++ addon support for adapter-node #7413

Closed
MilesWellsSVT opened this issue Oct 27, 2022 · 2 comments
Closed

C++ addon support for adapter-node #7413

MilesWellsSVT opened this issue Oct 27, 2022 · 2 comments

Comments

@MilesWellsSVT
Copy link

MilesWellsSVT commented Oct 27, 2022

Describe the problem

I need to be able to bundle .node files (C++ Addons).

I'm fine if this is immediately closed because of #3733, but because adapter-node no longer uses esbuild I'm not sure if my comment on that issue is relevant.

Describe the proposed solution

My knowledge in rollup and esbuild are quite lacking, but here is an esbuild plugin that would theoretically solve the problem. Since adapter-node switched to rollup from esbuild this isn't exactly a solution, but I've included it for reference since I don't know what else to do.

Alternatives considered

I've gotten the C++ addon I'm using to work by putting it in dependencies so it gets skipped for bundling. Then you can simply run node build to run and it works just fine on my local machine. So theoretically, for deployment, one could produce the build (with C++ addons in dependencies so they aren't bundled) and then install the non-bundled dependencies wherever the build gets deployed.

Importance

would make my life easier

Additional Information

Specifically I'm using Azure's MSAL Node extensions for account caching.

The node-resolve rollup plugin docs state the default for the extensions configuration includes .node files. I don't know why .node files don't work out of the box since adapter-node uses this plugin.

Here is a reproduction repo. All I did was install adapter-node and @azure/msal-node-extensions as well as using it in src/routes/+page.server.js.

image

For the "Alternatives considered" here's what I did:

  • pnpm run build and copy the build directory out somewhere else on my local machine
  • In the directory build was copied to, also copy package.json (I deleted all the devDependencies but I doubt that's necessary)
  • pnpm i in the same directory to install dependencies
  • node build to run the application

Here's some example output:

image

The false coming through the console when I navigate to localhost:3000 is from this line and it is false, as expected, since I ran this on a mac.

@Rich-Harris
Copy link
Member

The packages in question should go in dependencies — these will be ignored by esbuild. I'm not sure there's anything we need to do beyond that? Packages in dependencies (as opposed to devDependencies) are supposed to be installed wherever you run the deployment

@MilesWellsSVT
Copy link
Author

I believe my error was in thinking C++ addons were somehow portable in a way they could be bundled in any node application to be deployed anywhere so I was searching for a way to make bundling work with them. But that's not the case since the addons are compiled for specific architecture which happens on installation with tools such as node-gyp. Due to my ignorance this is a best guess, anyway.

So to conclude - my "alternative" is the correct way of handling C++ addons and I just figured it out through roundabout trial and error 😆

Thanks for your time!

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

No branches or pull requests

2 participants