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

335
Visualizações
Nodejs: use import in only one file

I have a project which is build using require, but now I need to use a package @nfteyez/sol-rayz, which only have support for ES6 import.

I cannot add type: module because there are lots of files.

I have tried changing file to mjs, but I get errors when importing it with require in another file.

I found in example that is possible when you enable module you can use import with:

// Define "require"
import { createRequire } from "module";
const require = createRequire(import.meta.url);

is there something similar for import? I am using node v17

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Go for dynamic import() function.

let solRayz = await import('@nfteyez/sol-rayz');

For complete suppression and use one common style, it is very difficult as the implicit packages have their own module system in their package files. For this particular problem, the following links might help

Complete flexibility of using module systems is not available as of now

What is the difference between .js and .mjs files?

https://nodejs.org/docs/latest/api/esm.html#esm_differences_between_es_modules_and_commonjs

https://www.geeksforgeeks.org/how-to-use-an-es6-import-in-node-js/

about 4 years ago · Juan Pablo Isaza Relatório

0

in node.js v14 and above, we can enable es module support by just add this in package.json

"type": "module"
about 4 years ago · Juan Pablo Isaza Relatório
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