Importing
Last updated
Last updated
There are packages that work just in the browser, just in react, just for gatsby, or just for node
And there are some that work for multiple like debug
working for node and browsers
ECMA Modules(import) webpack/babel often, async loaded
Absolute paths are currently not supported
Relative paths are resolved relative to current module path
automatically in , (mistakes into errors, simplifying/easier JS, anticpate future ECMA evolution)
CommonJS(require) node default, sync loaded
Have access to __filename
and __dirname
.mjs
extension in node:
Uses ECMA, but can cause problems if you use CommonJS modules too
Can import commonjs files, but .js cant use .mjs
Use std/esm to use .mjs in .jsj
main.js
Access Node builtin modules
Exporting
Importing
###Import (EMCAScript)
Exporting
Importing
Exporting Imports
TypeScript 3.8 adds a new syntax for type-only imports and exports.
import type
only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there’s no remnant of it at runtime. Similarly, export type
only provides an export that can be used for type contexts, and is also erased from TypeScript’s output.