Skip to content

Commit c1bee2b

Browse files
maschadachingbrain
andauthored
docs: add ESM section to avoid configuration issues (#1782)
Related #1776 --------- Co-authored-by: Alex Potsides <alex@achingbrain.net>
1 parent d853d12 commit c1bee2b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

doc/GETTING_STARTED.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Welcome to libp2p! This guide will walk you through setting up a fully functiona
55
- [Getting Started](#getting-started)
66
- [Install](#install)
77
- [Configuring libp2p](#configuring-libp2p)
8+
- [ESM](#esm)
89
- [Basic setup](#basic-setup)
910
- [Transports](#transports)
1011
- [Connection Encryption](#connection-encryption)
@@ -29,6 +30,27 @@ npm install libp2p
2930

3031
If you're new to libp2p, we recommend configuring your node in stages, as this can make troubleshooting configuration issues much easier. In this guide, we'll do just that. If you're more experienced with libp2p, you may wish to jump to the [Configuration readme](./CONFIGURATION.md).
3132

33+
### ESM
34+
35+
Since `libp2p@0.37.0` modules are now [ESM-only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
36+
37+
ESM is the module system for JavaScript, it allows us to structure our code in separate files without polluting a global namespace.
38+
39+
Other systems have tried to fill this gap, notably CommonJS, AMD, RequireJS and others, but ESM is [the official standard format](https://tc39.es/ecma262/#sec-modules) to package JavaScript code for reuse. This means that you need ensure your configuration uses the correct module system, if you are using Typescript, set the [`module` field in your tsconfig](https://www.typescriptlang.org/tsconfig#module) to `ES2022 ` or later e.g.
40+
41+
```json
42+
{
43+
"compilerOptions": {
44+
"module": "ES2022",
45+
"esModuleInterop": true,
46+
"target": "ES2022",
47+
"moduleResolution": "node"
48+
}
49+
}
50+
```
51+
52+
For more info on enablng ES modules in Node, see [this guide](https://nodejs.org/api/esm.html).
53+
3254
### Basic setup
3355

3456
Now that we have libp2p installed, let's configure the minimum needed to get your node running. The only modules libp2p requires are a [**Transport**][transport] and [**Crypto**][crypto] module. However, we recommend that a basic setup should also have a [**Stream Multiplexer**](streamMuxer) configured, which we will explain shortly. Let's start by setting up a Transport.

0 commit comments

Comments
 (0)