<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 7, 2022 at 9:39 AM Jérémy Lal <<a href="mailto:kapouer@melix.org">kapouer@melix.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 7, 2022 at 8:33 AM Yadd <<a href="mailto:yadd@debian.org" target="_blank">yadd@debian.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Package: nodejs<br>
Version: 16.13.2~dfsg-2<br>
Severity: normal<br>
<br>
Hi,<br>
<br>
starting from version 14, nodejs is able to run .mjs files. However,<br>
"import" method only works when dependency is available in node_modules<br>
directories. To avoid having to create node_modules/* links in each<br>
directory, it could be usefull to have node_modules links that points to<br>
nodejs in each /usr/(share|lib|lib/${DEB_MULTIARCH})/nodejs directory.<br>
<br>
Then only some links will be needed when a /usr/share/nodejs file tries<br>
to "import" a /usr/li/x86_64*/nodejs module.<br>
<br>
Alternative: modify nodejs to be able to search "import" modules in<br>
process.config.variables.node_relative_path<br></blockquote><div><br></div><div>I agree these should be added for native modules:</div><div>/usr/share/node_modules -> /usr/share/nodejs</div><div>and for binary modules:</div><div>/usr/lib/$(arch_triplet)/node_modules -> /usr/lib/$(arch_triplet)/nodejs</div><div><br></div><div>The case of a binary module importing a native module is trickier.</div><div>I think the javascript part of those modules should stay in /usr/share/nodejs,</div><div>and the actual compiled binary file be stored in /usr/lib/$(arch_triplet)/nodejs.</div><div><br></div><div>That way only the "binary loading" paths need a patch - which is expected, since</div><div>debian already is patching nodejs to get the correct paths from arch triplet.</div></div></div></blockquote><div><br></div><div>Update: esm loading of native addons "*.node" files shouldn't need additional patches,</div><div>because it isn't actually supported:</div><div><br></div><div>import * from 'addon.node'</div><div>> Unknown file extension ".node"...</div><div><br></div><div>See also <a href="https://github.com/nodejs/node/issues/40541">https://github.com/nodejs/node/issues/40541</a><br></div><div>which gives a way to do it from an es module:</div><div><br></div><div>> import { createRequire } from "module"</div><div>> export default createRequire(import.meta.url)("./native.node")</div><div><br></div><div>i believe createRequire follows the legacy resolution paths, to be tested.</div><div>If that's really the case, splitting "stuff" module into</div><div>/usr/share/node_modules/stuff (which tries to require ./build/stuff.node)</div><div>/usr/lib/$(arch)/node_modules/stuff/build/stuff.node</div><div>shouldn't need additional patches. A big "if".</div><div><br></div><div>Jérémy</div></div></div>