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

119
Vistas
export is not working when try to destructure in javascript import

I have two file: file A.js:

export default={
    name:"sample"
  }

file B.svelte:

import {name} from './A';

Error: name is not export from A.js

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are two problems there:

  1. That's now how you make the default export an object, you should remove the =.

  2. import is not destructuring, they just have a superficial resemblance to each other. You can't destructure during an import.

I would make the export a named export:

export let name = "sample";

...which would work with your import. Changes to name by the source module will show up in the imported binding for it (imports are live bindings to the original export).

But if you don't want to do that, here's how you export an object as the default export:

export default {
    name: "sample",
};

and then you have to import and destructure separately:

import obj from "./A.js";
const { name } = obj;

Note: The above is how standard JavaScript modules work according to specification. Bundlers may go beyond the spec when bundling code (for instance, may allow named import syntax when in fact you're destructuring a default exported objects), but if so, it's non-standard.

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