Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
How to link dynamic node modules without a file system?

Currently, I'm trying to develop a tool, that makes it possible to pack a JS-Module into tar-archive and then load it into Node.js dynamically and in-memory.

It does work perfectly, when importing a single JS-file that has no dependencies to other files. But when there are dependencies, I can't glue them together yet.

An example structure in the archive could look like this:

someArchive.tar.gz
- foo.js
- package.json
- lib
  - bar.js

The relationship between the two modules could look like this (foo.js):

import { something } from "./lib/bar.js";

To make it possible to use an archived JS-file in general, I'm using the "adm-zip"-npm-package, which allows me to deal with archives in-memory.

Important: I cannot use the file-system in any way for this project, unfortunately.

While the "adm-zip"-package enables me to handle the data itself, I am constructing the module-object on my own using the Module-Constructor:

const Module = module.constructor;
const m = new Module();
const moduleName = "<Filename relative to archive root>";
m.children = [ <the module-object from bar.js> ];
m._compile(<fooContentFromArchive>, moduleName);
m.path = <moduleName without filename>;
m.id = moduleName;
m.filename = moduleName;
return m;

As you can see, I already put the dependent module-object into the children-array of the superior module-object. As far as I understood, the children-array is containing dependent modules.

But unfortunately, it doesn't work.

I know, that what I am doing is very special and hacky, and especially using the file-system would make everything much easier, but as mentioned, I have the limitation, that I don't have access to the filesystem.

Also, I haven't found any npm-packages, that are enabling me to do solve the problem (If I get it working, I could create one).

Do you have any idea, what I could try?

Thank you in advance!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda