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