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

128
Visualizações
rewrite require to import statement

I am trying to use https://www.npmjs.com/package/json-bigint with native BigInt support. In CommonJS I'd do:

var JSONbigNative = require('json-bigint')({ useNativeBigInt: true });

What is the ES6 syntax equivalent? This is not working:

import  * as JSONBigIntWrapper from 'json-bigint';
const JSONBigInt = JSONBigIntWrapper({useNativeBigInt: true});

as it complains that JSONBigIntWrapper is not a function.

What are the generic rules for rewriting rewrite to import?

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

0

You can rely on using the default keyword when importing the default export from a module.

import {default as _JBI} from 'json-bigint';
const JSONBigNative = _JBI({useNativeBigInt: true});

This is also the only syntax which works when using dynamic import syntax:

const {default: _JBI} = await import('json-bigint');
const JSONBigNative = _JBI({useNativeBigInt: true});
about 4 years ago · Juan Pablo Isaza Relatório

0

With ES6 imports, importing * is not the equivalent of what require() does.

What you are looking to get is the default module export, as shown in the code below

import whatever_you_want_the_default_to_be_named, {} from 'json-bigint'
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