https://github.com/thdk/require-esm-demo
https://github.com/thdk/require-esm-demo
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/thdk/require-esm-demo
- Owner: thdk
- Created: 2025-02-06T14:53:28.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-07T09:26:50.000Z (over 1 year ago)
- Last Synced: 2025-03-05T10:02:23.387Z (over 1 year ago)
- Language: TypeScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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;
}>();
}
}
```