Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Support "exports" and "imports" in package.json #1659

Open
2 of 4 tasks
JavaScriptBach opened this issue Aug 9, 2024 · 2 comments
Open
2 of 4 tasks

Comments

@JavaScriptBach
Copy link

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

I work in a Typescript mono-repo, where all our imports are bare imports instead of relative imports. We define exports and imports in package.json to control what each package exports. It would be great if tsoa knew how to resolve these imports.

See https://github.com/JavaScriptBach/tsoa-repro for an example.

Current Behavior

tsoa does not know how to resolve these imports:

Generate routes error.
 GenerateMetadataError: No declarations found for referenced type User.
    at TypeResolver.getModelTypeDeclarations (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:871:62)
    at TypeResolver.calcRefTypeName (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:536:39)
    at TypeResolver.calcTypeReferenceTypeName (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:712:34)
    at TypeResolver.getReferenceType (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:721:35)
    at TypeResolver.resolveTypeReferenceNode (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:468:21)
    at TypeResolver.resolve (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:293:21)
    at TypeResolver.resolveTypeReferenceNode (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:458:93)
    at TypeResolver.resolve (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/typeResolver.js:293:21)
    at MethodGenerator.Generate (/Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/methodGenerator.js:62:78)
    at /Users/philliphuang/tsoa-repro/node_modules/@tsoa/cli/dist/metadataGeneration/controllerGenerator.js:46:41
error Command failed with exit code 1.

Steps to Reproduce

https://github.com/JavaScriptBach/tsoa-repro

Context (Environment)

Version of the library: 6.4.0
Version of NodeJS: 18.14.0

  • Confirm you were using yarn not npm: [x]

Detailed Description

It would be nice if tsoa understand how to resolve these fields:

These fields have been around since ~Node 12 and all major tooling (e.g. Typescript, bundlers) know how to understand them.

Currently, I can hack around this issue by passing custom tsconfig options to tsoa. But this is not ideal because I have to define the import paths in 2 different locations (package.json and in tsoa).

Breaking change?

This could break generation depending on what users have defined in their exports or imports in package.json.

@github-actions github-actions bot added Stale and removed Stale labels Sep 9, 2024
@github-actions github-actions bot added Stale and removed Stale labels Oct 10, 2024
@WoH
Copy link
Collaborator

WoH commented Oct 31, 2024

Is the file that declares the User model included in tsc's files?

Repository owner deleted a comment from github-actions bot Oct 31, 2024
Repository owner deleted a comment from github-actions bot Oct 31, 2024
Repository owner deleted a comment from JavaScriptBach Oct 31, 2024
Repository owner deleted a comment from github-actions bot Oct 31, 2024
Repository owner deleted a comment from JavaScriptBach Oct 31, 2024
@JavaScriptBach
Copy link
Author

Why does tsc matter here? The rules to resolve the imports are defined in package.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants