Learn JavaScript

Lesson 2 of 9 ¡ Modules: import, export and How Files Find Each Other

Module 11 ¡ Modules: import, export and How Files Find Each Other

Every Module Rule, One by One: Exports, Imports, Paths and the Two Systems

Free with an accountReading

Kenji moves a shop's code from one big file into twenty modules. On day one he meets six new error messages. One says a module "does not provide an export named" something. Another says it cannot find a module that is plainly there. Each message is a rule he did not know yet.

Checking what this lesson needs for youâ€Ļ

What is inside Every Module Rule, One by One: Exports, Imports, Paths and the Two Systems

  1. Named exports
  2. An export list, with renaming
  3. The default export
  4. Named imports, renamed
  5. The default import
  6. The namespace import
  7. Re-exporting from another module
  8. The module scope: strict mode and no globals
  9. Top-level await
  10. How a browser loads a module
  11. How Node decides: ES module or CommonJS
  12. require and module.exports, in full
  13. Paths and file endings
  14. Dynamic import()
  15. ES modules against CommonJS