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

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

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 Report

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