remix icon indicating copy to clipboard operation
remix copied to clipboard

feat(remix-dev/compiler): support native `.node` files

Open nicksrandall opened this issue 3 years ago • 9 comments
trafficstars

This PR enables support for users to include "native" (.node) modules into their server bundles (when using NodeJS).

Libraries like sharp (awesome for for image processing) are written in a lower-level language than NodeJS and then are compiled as a "native" module to be used in a Node environment.

Discussion: #2560

  • [ ] Docs
  • [ ] Tests

nicksrandall avatar Apr 04 '22 15:04 nicksrandall

Hi @nicksrandall,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

remix-cla-bot[bot] avatar Apr 04 '22 15:04 remix-cla-bot[bot]

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

remix-cla-bot[bot] avatar Apr 04 '22 15:04 remix-cla-bot[bot]

⚠️ No Changeset found

Latest commit: 2fec55f4d40c8f2700d325f9b111626286369f15

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 18 '22 12:07 changeset-bot[bot]

Sorry @nicksrandall, I did a whopsy while trying to change the base branch (code changes need to target dev). I'll get this fixed unless you do.

machour avatar Jul 18 '22 13:07 machour

@MichaelDeBoey I don't particularly care which PR gets merged, but I have no ability to edit this here. I think you need the node system check, the compiler changes, the path detection code, and everything else I had to do in my PR. We're running this change in Prod right now to serve .node files, and it seems to work well.

benwis avatar Jul 21 '22 05:07 benwis

@benwis I'll give you access to my branch. I also don't care which PR gets merged so if it's easier to close then and re-open yours, we can do that.

nicksrandall avatar Jul 22 '22 14:07 nicksrandall

@nicksrandall Thanks for inviting me! I'm happy to do it here, I'll dig in and address the comments today. I'd love to see this and the WASM changes merged!

benwis avatar Jul 22 '22 15:07 benwis

Let's keep this branch open then 👍

MichaelDeBoey avatar Jul 22 '22 15:07 MichaelDeBoey

@MichaelDeBoey @nicksrandall I have updated this repo for the changes in Remix 1.7.1 and reapplied the changes made, plus some of mine. I'm not sure how to get this pull request to update based on the status of the dev branch of the parent repo though. It seems to be stuck.

benwis avatar Nov 09 '22 22:11 benwis

@MichaelDeBoey any updates on this. This is a blocker for me.

nicksrandall avatar Jan 29 '23 03:01 nicksrandall

@nicksrandall Please rebase your branch onto latest dev & resolve conflicts I'll inform the team to have a look at this afterwards

MichaelDeBoey avatar Jan 30 '23 02:01 MichaelDeBoey

@nicksrandall I'd like to get this merged but there are comments left by @jacob-ebey that still haven't been addressed, and the server compiler code was moved into compilerServer.ts so some of the code needs to be moved over. If you can get this cleaned up and address outstanding issues, I'll merge.

chaance avatar Feb 09 '23 12:02 chaance

I'll look at this today and see if I can get it updated.

nicksrandall avatar Feb 09 '23 14:02 nicksrandall

@chaance The solutions here has gotten more simple since esbuild added support for the copy loader.

See: https://github.com/evanw/esbuild/issues/1051#issuecomment-1156783762

This should just work when app imports a .node file directly.

One potential gotcha that I feel like I should point out is that packages that ship .node files have to compile a node file per OS/Architecture (like linux/amd64). Sometimes, the library author will then use dynamic require statements to require the appropriate node file. Esbuild can not know the path of a dynamic require statement so this will not work in those cases.

In such a case, the user will just need to mark the package as "external" (or in Remix case, exclude it from being bundled) and then it should just work.

nicksrandall avatar Feb 09 '23 15:02 nicksrandall

@benwis I know you also worked on this... You comfortable just using the copy loader for .node files?

nicksrandall avatar Feb 09 '23 15:02 nicksrandall

In such a case, the user will just need to mark the package as "external" (or in Remix case, exclude it from being bundled) and then it should just work.

I think that's probably fine for now. The same is true for any other dynamic file import.

chaance avatar Feb 09 '23 15:02 chaance

I think that's probably fine as well, although I haven't found time to test it :)

benwis avatar Mar 06 '23 21:03 benwis

🤖 Hello there,

We just published version v0.0.0-nightly-66b33a8-20230310 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

github-actions[bot] avatar Mar 10 '23 07:03 github-actions[bot]

I am still running into this issue when trying to install adminjs.

✘ [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");

serverDependenciesToBundle is not fixing this

serverDependenciesToBundle: ["fsevents"]

MoSattler avatar May 09 '23 16:05 MoSattler