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

118
Visualizações
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 Respostas
Responde à pergunta

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 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