privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
9.71k stars 152 forks source link

TypeError: ClassName is not a constructor #674

Closed chanakya-svt closed 2 days ago

chanakya-svt commented 2 days ago

Acknowledgements

Minimal reproduction URL

https://github.com/chanakya-svt/crd2pulumi-tsx-repro

Problem & expected behavior (under 200 words)

The reproduction repo has a readme with the error, but in short when importing and invoking a class I am receiving the following error:

/apps/crds/index.ts:3
new certManagerIssuers.cert_manager.v1.Issuer(
  ^
TypeError: import_src.certManagerIssuers.cert_manager.v1.Issuer is not a constructor

Versions:

Bugs are expected to be fixed by those affected by it

Compensating engineering work will speed up resolution and support the project

privatenumber commented 2 days ago

Sorry but your reproduction is not minimal. I'm sure you don't need all those dependencies. Please minimize it down to under 5 files.

Happy to reopen the issue once updated.

chanakya-svt commented 1 day ago

@privatenumber

Thank you for your quick response regarding the issue. The reproduction repository is minimal, containing just one file (apps/crds/index.ts), which serves as the main program.

All other files within libs/custom-resource-definitions are automatically generated by the crd2pulumi tool. Each of these files includes a warning comment at the top, like the one below:

// *** WARNING: this file was generated by crd2pulumi. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***

As a result, the files in libs/custom-resource-definitions should be treated as external libraries, and no modifications can be made to them. This means that apps/crds/index.ts is the only file that can be modified along with nx(project.json), pulumi(Pulumi.yaml) and typescript(tsconfig.*.json) metadata files.

Also removed all the unused packages from package.json and unused code from libs/custom-resource-definitions(like the certificates folder)

chanakya-svt commented 17 hours ago

@privatenumber This also looks like a nested import issue. If I change the import in apps/crds/index.ts from

import { certManagerIssuers } from '../../libs/custom-resource-definitions/src/';

new certManagerIssuers.cert_manager.v1.Issuer(...)

to

import { Issuer } from '../../libs/custom-resource-definitions/src/cert-manager/issuers/cert_manager/v1/issuer';

new Issuer(...)

I get no error and everything executes correctly.

privatenumber commented 8 hours ago