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

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

Merged
merged 1 commit into from
Mar 9, 2023

Conversation

nicksrandall
Copy link
Contributor

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Apr 4, 2022

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
Copy link
Contributor

remix-cla-bot bot commented Apr 4, 2022

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

@changeset-bot
Copy link

changeset-bot bot commented Jul 18, 2022

⚠️ No Changeset found

Latest commit: 2fec55f

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

@machour machour changed the base branch from main to dev July 18, 2022 12:40
@machour machour changed the base branch from dev to main July 18, 2022 12:42
@machour
Copy link
Collaborator

machour commented Jul 18, 2022

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.

@MichaelDeBoey MichaelDeBoey changed the base branch from main to dev July 18, 2022 15:18
@MichaelDeBoey MichaelDeBoey changed the title feat(compiler): Allow native .node files #2560 feat(remix-dev/compiler): allow native .node files Jul 18, 2022
@MichaelDeBoey MichaelDeBoey changed the title feat(remix-dev/compiler): allow native .node files feat(remix-dev/compiler): support native .node files Jul 18, 2022
Copy link
Member

@MichaelDeBoey MichaelDeBoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicksrandall I closed #3263 by @benwis in favor of this one, since you started first on this idea.

Could you please look into that PR & see if we also want to only enable this plugin on node based platforms?
Can you also check if we need the extra compiler changes that were implemented.
Copying over the docs would be a good thing as well I think (please add @benwis as a co-author & in the contributors list)

packages/remix-dev/compiler.ts Outdated Show resolved Hide resolved
@benwis
Copy link
Contributor

benwis commented Jul 21, 2022

@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.

@nicksrandall
Copy link
Contributor Author

@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.

@benwis
Copy link
Contributor

benwis commented Jul 22, 2022

@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!

@MichaelDeBoey
Copy link
Member

Let's keep this branch open then 👍

@benwis
Copy link
Contributor

benwis commented Nov 9, 2022

@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.

@nicksrandall
Copy link
Contributor Author

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

@MichaelDeBoey
Copy link
Member

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

@chaance
Copy link
Collaborator

chaance commented Feb 9, 2023

@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 chaance added the needs-response We need a response from the original author about this issue/PR label Feb 9, 2023
@nicksrandall
Copy link
Contributor Author

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

@nicksrandall
Copy link
Contributor Author

nicksrandall commented Feb 9, 2023

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

See: evanw/esbuild#1051 (comment)

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
Copy link
Contributor Author

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

@github-actions github-actions bot removed the needs-response We need a response from the original author about this issue/PR label Feb 9, 2023
@chaance
Copy link
Collaborator

chaance commented Feb 9, 2023

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.

@benwis
Copy link
Contributor

benwis commented Mar 6, 2023

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

@chaance chaance merged commit d49fa0c into remix-run:dev Mar 9, 2023
@github-actions
Copy link
Contributor

🤖 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!

@nicksrandall nicksrandall deleted the nick/native-modules branch March 15, 2023 14:59
fernandojbf pushed a commit to fernandojbf/remix that referenced this pull request Mar 21, 2023
@MoSattler
Copy link

MoSattler commented May 9, 2023

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"]

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

Successfully merging this pull request may close these issues.

6 participants