Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!