From 25f369a25a4be15eb3c4859eb13d8cdc5a9183d9 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 23 Feb 2023 21:43:19 +0400 Subject: [PATCH] feat(docs): Add information about ESM modules format in Node.js apps (#275) --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 13f44efe..b54cae64 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,26 @@ Adding the Fluence JS client for your web application is very easy. ### 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: ```