Archived post: posted sometime between 2016 and 2022.

import m = require("m") vs import * as m from "m"

If you think you understand quantum mechanics, you don't understand quantum mechanics. ~ Probably Richard Feynman

We can say the same about ECMAScript Modules. If anything below does not seem quite right, please let me know @shaunluttin on Twitter.

Importing Modern Modules

Before we compare the import = and import * syntax, lets look at two ways to import modern ECMAScript modules .

import m from "module"

import { m } from "module"

Import of CommonJS/AMD Modules

Though the modern imports are part of ECMAScript 6 Modules' (ESM) specification, neither NodeJS nor major browsers support the ESM loader yet. NodeJS marks ESM as experimental and has a proposal to make ESM interoperate with its existing CommonJS module loader. Major browsers are starting to support ESM . That means we will eventually have ESM as a common module loader API for the server and the browser. In the meantime, we must use Babel or TypeScript to transpile ECMAScript Modules down to CommonJS, AMD, or some other module syntax. Importantly: the emerging ECMA Modules' loader needs to be compatible with the NodeJS/CommonJS module loader. That need for interop is why we have the following two (plus one) import styles:

import m = require("module")

import * as m from "module"

const m = require("module")

Conclusion

Use import = only to consume legacy modules; avoid import ... as entirely, and approach ECMAScript modules with intellectual humility.