octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
6.84k stars 1k forks source link

[BUG]: An import path cannot end with a '.ts' extension #2597

Closed kanocarra closed 6 months ago

kanocarra commented 6 months ago

What happened?

Upgraded from version 2.1.0 to 3.1.2 of octokit and receiving the above error when building in typescript:

import type { Logger } from "./createLogger.ts";
                              ~~~~~~~~~~~~~~~~~~~
node_modules/@octokit/webhooks/dist-types/types.d.ts:4:40 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './generated/webhook-names' instead.

If I downgrade to 2.x.x I no longer have this problem and can see in the @octokit/webhooks/dist-types/types.d.ts folder that the import changes to

import type { Logger } from "./createLogger";

Thus removing the .ts extension.

I have added allowImportingTsExtensions: true in my tsconfig.json but still see this error? I would expect this to build without error.

Anyone have any ideas?

Versions

Octokit v3.2.1 Node.js 18.15 Typescript 4.7.4

Relevant log output

node_modules/@octokit/webhooks/dist-types/middleware/node/types.d.ts:1:29 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing '../../createLogger' instead.

1 import type { Logger } from "../../createLogger.ts";
                              ~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@octokit/webhooks/dist-types/types.d.ts:3:29 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './createLogger' instead.

3 import type { Logger } from "./createLogger.ts";
                              ~~~~~~~~~~~~~~~~~~~
node_modules/@octokit/webhooks/dist-types/types.d.ts:4:40 - error TS2691: An import path cannot end with a '.ts' extension. Consider importing './generated/webhook-names' instead.

4 import type { emitterEventNames } from "./generated/webhook-names.ts";
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 3 error(s).

Code of Conduct

github-actions[bot] commented 6 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

wolfy1339 commented 6 months ago

Thank you for bringing this up!

Indeed, the import is using a .ts extension. While that is allowed using the allowImportingTsExtensions that only works with the noemit option.

The correct fix would be to simply replace it with a .js extension

Would you like to submit a PR with a fix?

kanocarra commented 6 months ago

Hey @wolfy1339 I actually managed to fix it! Unfortunately I can't use the noEmit option as this is for a nestJS runtime so need the built files output.

Upgrading to typescript v5.3.3 seemed to fix the build issue so all resolved now ✅ For anyone who has the same issue, just upgrade your typescript! Happy to leave as is unless you think worth fixing?

Thanks

wolfy1339 commented 6 months ago

I think you overlooked the last part of my last comment.

I understand you can't use the noEmit option, I wasn't suggesting as such, just pointing it out.

Upgrading Typescript definitely does help.

Replacing the .ts with .js in the offending import would fix this problem for everybody