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

Incorrect .node module require #3294

Closed
stalker8610 opened this issue Aug 6, 2023 · 3 comments
Closed

Incorrect .node module require #3294

stalker8610 opened this issue Aug 6, 2023 · 3 comments

Comments

@stalker8610
Copy link

Hi guys!
Either here is a bug with .node modules requiring or I can't understand what is wrong with my script.

Here is a repo with bug reproduction

How to reproduce:

  1. clone repo
  2. run 'npm i'
  3. run not built source - 'node index' to see in console that ActiveX is a function (is expected behavior)
  4. run 'npm run build'
  5. run 'node build/index.cjs' to see the bug in built

Expected behavior - requires content of .node module, then uses it as a module.
Current behavior - it seems like after build it tries to use PATH to module instead of it's content. Please see the screenshots, if I add 'require(..)' it starts work right.

bug
fixed

@evanw
Copy link
Owner

evanw commented Aug 6, 2023

You explicitly told esbuild to do this when you passed --loader:.node=file. That's what the file loader does: https://esbuild.github.io/content-types/#file. This is not a bug with esbuild.

@stalker8610
Copy link
Author

omg, I'm blind :) thanks, I just need to use 'copy' mode

@evanw
Copy link
Owner

evanw commented Aug 6, 2023

I'm closing this issue because this is not a bug. You told esbuild to embed the path to the file in the bundle as a string, so that's what it did. You don't have to do that. There are other loaders for other things. For example, you can use the copy loader if you want esbuild to continue reference the file instead.

But you should probably just exclude the relevant package for the bundle entirely because many packages with native .node modules expect a arrangement of files on the file system and don't like being copied to a different location. This is covered in the getting started instructions for node: https://esbuild.github.io/getting-started/#bundling-for-node.

@evanw evanw closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2023
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