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)
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.
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 toconst {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.