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

support for .node extension like webpack does #3963

Open
adumesny opened this issue Nov 4, 2024 · 3 comments
Open

support for .node extension like webpack does #3963

adumesny opened this issue Nov 4, 2024 · 3 comments

Comments

@adumesny
Copy link

adumesny commented Nov 4, 2024

I'm using Nx + angular 18 which supports esbuild by default for new project, though I've read Angular doesn't expose esbuild options.
Large existing project (came from ng16 and webpack) which has some depencies on a native .node extension I'm trying to remove without sucess.

when compiling I get these errors

> yarn build
X [ERROR] No loader is configured for ".node" files: node_modules/@node-rs/jieba-win32-x64-msvc/jieba.win32-x64-msvc.node
    node_modules/@node-rs/jieba/index.js:104:36:
      104 │ ...        nativeBinding = require('@node-rs/jieba-win32-x64-msvc');

Q: does esbuild support .node at all ?
looking at #3947 (comment) it doesn't appear to
| All require() calls resolve to JavaScript files that esbuild can understand (e.g. not to .node native extensions)

Q: what about .wasm ? I assume same.

I've spent days looking for plugins (or alternative to using that deep depencies) and not finding something I can use in Angular (which may not expose all the esbuild options).

@hyrious
Copy link

hyrious commented Nov 4, 2024

  1. You can add --loader:.node=copy to copy the .node file to distribution. Playground

  2. There's an example wasm plugin on the website: https://esbuild.github.io/plugins/#webassembly-plugin

    Note that to make the wasm plugin work you must use an analyzable import/require which directly points to the wasm file.

    If your target environment is Node.js, it actually has an experimental native wasm-import support. In which case you can just use the copy loader again to do the job.

@adumesny
Copy link
Author

adumesny commented Nov 5, 2024

@hyrious thanks

  1. I had tried passing an arg but since I'm using NX and angular, the params must be parsed and rejected before it goes to esbuild (which has hidden settings according to angular lib I've read so far)
> yarn build
yarn run v1.22.22
$ nx build --configuration=production --loader:.node=copy

> nx run shell:build:production --loader:.node=copy

 NX   'loader:' is not found in schema
  1. will have to check it out

but since I'm building for browser (not node.js on server) not sure why 'path' + '.node' file would be needed anyway (incompatible with browsers).

@hyrious
Copy link

hyrious commented Nov 5, 2024

I myself didn't use nx and angular so the correct options needs yourself to find out.

For nx I googled this: https://nx.dev/recipes/running-tasks/pass-args-to-commands#:~:text=Providing%20the%20%22%2D%2Dargs%22%20option where it seems you need either defining custom options or use --args="..." to pass arguments to commands.

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