forked from libp2p/js-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add ESM section to avoid configuration issues (libp2p#1782)
Related libp2p#1776 --------- Co-authored-by: Alex Potsides <[email protected]>
- Loading branch information
1 parent
d853d12
commit c1bee2b
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ Welcome to libp2p! This guide will walk you through setting up a fully functiona | |
- [Getting Started](#getting-started) | ||
- [Install](#install) | ||
- [Configuring libp2p](#configuring-libp2p) | ||
- [ESM](#esm) | ||
- [Basic setup](#basic-setup) | ||
- [Transports](#transports) | ||
- [Connection Encryption](#connection-encryption) | ||
|
@@ -29,6 +30,27 @@ npm install libp2p | |
|
||
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). | ||
|
||
### ESM | ||
|
||
Since `[email protected]` modules are now [ESM-only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). | ||
|
||
ESM is the module system for JavaScript, it allows us to structure our code in separate files without polluting a global namespace. | ||
|
||
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. | ||
|
||
```json | ||
{ | ||
"compilerOptions": { | ||
"module": "ES2022", | ||
"esModuleInterop": true, | ||
"target": "ES2022", | ||
"moduleResolution": "node" | ||
} | ||
} | ||
``` | ||
|
||
For more info on enablng ES modules in Node, see [this guide](https://nodejs.org/api/esm.html). | ||
|
||
### Basic setup | ||
|
||
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. | ||
|