An open API service indexing awesome lists of open source software.

https://github.com/thdk/require-esm-demo


https://github.com/thdk/require-esm-demo

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# Demo application using nestjs (commonjs) which imports got (esm module)

This applicaiton requires node 22.12.0 or higher.

```sh
# Require force because we are using beta typescript version which doesn't match peerDependency requirements of dependencies.
npm install --force
npx nx serve
```

```json
{
"//": "package.json",
"...": "...",
"type": "commonjs",
"dependencies": {
"...": "...",
"got": "^14.4.5"
},
"devDependencies": {
"...": "...",
"typescript": "5.8.0-beta"
},
"overrides": {
"typescript": "5.8.0-beta"
},
"engines": {
"node": ">=22.12.0"
}
}
```

```json
{
"//": "tsconfig.json",
"compilerOptions": {
"...": "...",
"moduleResolution": "nodenext",
"module": "NodeNext"
},
"...": "..."
}
```

```ts
// app.service.ts
import { Injectable } from '@nestjs/common';

import got from 'got'; // <-- importing esm module

@Injectable()
export class AppService {
async getData() {
return await got.get('https://dummyjson.com/test').json<{
status: string;
method: string;
}>();
}
}
```