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

152
Visualizações
wildcard import in javascript... does it work using `with` under the hood?

So I know imports can be replaced with require.

import {x} from 'x' is equivalent to const {x} = require('x').

But what about import * from 'x' ? the only thing that I can imagine it being translated to is with(require('x')){... }.

Yet with statements are frown upon, aren't they? (because you don't know in compile time how a reference will be resolved)

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

0

import * from "x";

is not valid JS.

import * as x from "x";

is.

How is that different from

import x from "x";

?

Well, the latter requires you to have a default export, while the former takes all the exports and groups them into one object.

about 4 years ago · Juan Pablo Isaza Relatório

0

I think you have the syntax confused. This:

import * from 'x'

is not valid. What you can do is:

import * as x from 'x';

This puts all the exports from the x file into the namespace (which is, for the most part, just a JavaScript object whose properties and default correspond to the names of the exports). The x identifier that gets imported refers to this namespace.

Also

import {x} from 'x' is equivalent to const {x} = require('x').

is not correct - require is CommonJS syntax, and import/export is ES6 module syntax. They're not interchangeable by default, though they do very similar things.

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