'How to solve Error: Cannot find module '<path-to>/my-app/node_modules/unenv/runtime/fetch.cjs' when trying to import unjs/unenv functions?

I'm developing a NestJS app, and I need to use a method provided by https://www.npmjs.com/package/unenv (https://github.com/unjs/unenv). But when trying to import it like

import { createCall } from "unenv/runtime/fetch";

I get the following error:

Error: Cannot find module '<path-to>/my-app/node_modules/unenv/runtime/fetch.cjs'
...

I found the issue on the Github repo of someone asking whether this package supports ESBuild (https://github.com/unjs/unenv/issues/32) so I checked my tsconfig.json but the module is set to commonjs

{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false
  }
}

Or is it that I need to change the target to something else? Is there a way I can make a bridge without having to change the configurations (as I potentially could run into other errors)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source