In Node.js, require is used to load modules, while import is used in ECMAScript modules (ESM modules) for loading other modules, either statically or dynamically.
The major difference between require and import is that require will automatically scan node_modules to find modules, but import, which comes from ES6, won’t.
Most people use Babel to compile import and export, which makes import act the same as require.
- require is more of dynamic analysis, and import is more of static analysis.
- require throws error at runtime, and import throws error while parsing.
- require is nonlexical and import is lexical.