From 93c63940291e6ce946f7d1d1a285e134b73b59cf Mon Sep 17 00:00:00 2001 From: Yash Kulshrestha Date: Sun, 7 Nov 2021 00:03:14 -0700 Subject: [PATCH] docs: added a note about importing the module in TypeScript (#474) --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4757390a..4bb2d62a 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,20 @@ Note: When using Node that supports [conditional exports](https://nodejs.org/api #### Use in **TypeScript**: -Import or require based on the environment (see above). +Import or require based on the environment (see above). If you want to use the CommonJS module syntax (`require`), you'll need to install the Node.js types from the `DefinitelyTyped` repository. + +``` +npm install @types/node +``` + +If you want to use the ESM syntax (`import`), you will need to include the following options in your `tsconfig.json`. + +```json +{ + "allowSyntheticDefaultImports": true, + "esModuleInterop": true +} +``` If you get errors stating: `Cannot find name 'BigInt'`, add [`"esnext.bigint"`](https://github.com/microsoft/TypeScript/blob/master/src/lib/esnext.bigint.d.ts) or [`"esnext"`](https://github.com/microsoft/TypeScript/blob/master/src/lib/esnext.d.ts) to your `tsconfig.json` file, under `"lib"`: