Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda