In nodejs require
is implemented in a similar way as is done with requirejs
. It is not a language feature but an ordinary function.
If you switch into debugging mode in node.js you will see that each fill is wrapped into a function:
(function( exports, require, module, __filename, __dirname) {
// the original source of the file
})
import
on the other hand is part of the ES6 specs.
Internally node.js would do that same for import
and require
, just with another syntax. TypeScript or WebPack will transpile the import
to their own internal syntax that is similar to the one above.
And the browser support of import
can be seen here:
MDN: import