Skip to content

NestJS app does not compile when typescript-functional-extensions package is referenced #3

Closed
@xShivan

Description

@xShivan

Hello.

First I'd like to say that I really appreciate the hard work you've put into the library. I'm coming from the C# world into the TypeScript and now I can use my favorite library in TypeScript!

I'm currently developing applications using NestJS. When I try to reference the library it throws me compilation errors like below.

When I copy source code of the library into my project everything runs just fine.

[8:52:59 AM] File change detected. Starting incremental compilation...

[8:52:59 AM] Found 0 errors. Watching for file changes.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/michal/dev/test/node_modules/typescript-functional-extensions/dist/index.js
require() of ES modules is not supported.
require() of /Users/michal/dev/test/node_modules/typescript-functional-extensions/dist/index.js from /Users/michal/dev/test/dist/app.service.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/michal/dev/test/node_modules/typescript-functional-extensions/package.json.

    at new NodeError (internal/errors.js:322:7)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1102:13)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.<anonymous> (/Users/michal/dev/test/src/app.service.ts:2:1)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)

This is a sample service where I use it:

import { Injectable } from '@nestjs/common';
import { Result } from 'typescript-functional-extensions';

@Injectable()
export class AppService {
  getHello() {
    return Result.success().map(() => 'test');
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Reference typescript-functional-extensions in NestJS project.
  2. Run start or start:dev script.
  3. Error like above should be present in console.

Expected behavior
App should run successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions