feat(docs): Add information about ESM modules format in Node.js apps (#275)

This commit is contained in:
Pavel 2023-02-23 21:43:19 +04:00 committed by GitHub
parent ef9fb2fbbd
commit 25f369a25a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,26 @@ Adding the Fluence JS client for your web application is very easy.
### Node.js Apps ### Node.js Apps
**Prerequisites:**
The Fluence JS Client only supports the ESM format. This implies that a few preliminary steps are required if your project is not already using ESM:
- Add `"type": "module"` to your package.json.
- Replace `"main": "index.js"` with `"exports": "./index.js"` in your package.json.
- Remove `'use strict';` from all JavaScript files.
- Replace all `require()`/`module.export` with `import`/`export`.
- Use only full relative file paths for imports: `import x from '.';``import x from './index.js';`.
If you are using TypeScript:
- Make sure you are using TypeScript 4.7 or later.
- Add [`"module": "ESNext", "target": "ESNext", "moduleResolution": "nodenext"`](https://www.typescriptlang.org/tsconfig#module) to your tsconfig.json.
- Use only full relative file paths for imports: `import x from '.';``import x from './index.js';`.
- Remove `namespace` usage and use `export` instead.
- You must use a `.js` extension in relative imports even though you're importing `.ts` files.
**Installation:**
1. Install the following packages: 1. Install the following packages:
``` ```