Skip to content

Allow consumers to disable skipLibCheck by adding // @ts-ignore to imports for dependencies that might not ever be added? #14066

Closed

Description

@700software

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @sentry/[email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@sentry/nextjs/build/types/config/types.d.ts b/node_modules/@sentry/nextjs/build/types/config/types.d.ts
index 48a1953..f9386d2 100644
--- a/node_modules/@sentry/nextjs/build/types/config/types.d.ts
+++ b/node_modules/@sentry/nextjs/build/types/config/types.d.ts
@@ -1,5 +1,6 @@
 import type { GLOBAL_OBJ } from '@sentry/utils';
 import type { SentryWebpackPluginOptions } from '@sentry/webpack-plugin';
+// @ts-ignore
 import type { DefinePlugin, WebpackPluginInstance } from 'webpack';
 export type { WebpackPluginInstance };
 export type ExportedNextConfig = NextConfigObject | NextConfigFunction;

This issue body was partially generated by patch-package.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 23, 2024
  2. s1gr1d commented on Oct 24, 2024

    @s1gr1d
    Member

    Hello, thanks for raising this!
    Can you elaborate the problem you had before adding // @ts-ignore?

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 24, 2024
  4. moved this to Waiting for: Community in GitHub Issues with 👀 3on Oct 24, 2024
  5. 700software commented on Oct 24, 2024

    @700software
    Author

    In our project we changed our tsconfig.json skipLibCheck from true (default) to false

    The reason we did this was to get red underlines and type check errors in typos in our .d.ts files since we use those extensively for internal types, and especially complex type transformations. (The reason we name our internal files .d.ts instead of .ts is not to export them, but just to provide clarity to the broader team that there is no runtime code in those files.)

    With skipLibCheck we couldn't get checks in those files.

    Now that skipLibCheck is turned off, we have noticed a handful of libraries, including yours will block our app from type-checking/building.

    Image

    Some of these we fixed by bumping our React version or @types/node version.

    But for sentry (and a few others) we saw no fix because your types.d.ts file imports a dependency we don't use: webpack.
    Image

    Error: node_modules/@sentry/nextjs/build/types/config/types.d.ts(3,58): error TS2307: Cannot find module 'webpack' or its corresponding type declarations.

    So my proposal is to add // @ts-ignore to "optional dependency imports" if you want to support skipLibCheck: false consumers.

    However if you don't want to support this use case I totally understand and you may close the issue. I can just continue using patch-package.

  6. moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 24, 2024
  7. Lms24 commented on Oct 28, 2024

    @Lms24
    Member

    Hi @700software thanks for explaining! I have to admit this is the first time that we're hearing about this import from webpack being a problem. We'd like to help you out as much as possible but I'm afraid adding a ts-ignore to this import might in turn have type checking implications on our end which I'd like to avoid.

    But for sentry (and a few others) we saw no fix because your types.d.ts file imports a dependency we don't use: webpack.

    This confuses me a bit: If you're using NextJS I'm fairly sure that you will have webpack as a dependency. It's probably not listed in your package.json but its a transitive dependency of NextJS since it relies on webpack. At least to my knowledge. I'm curious to learn more here :)

  8. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 28, 2024
  9. 700software commented on Oct 28, 2024

    @700software
    Author

    To answer your question, Next.js doesn't use webpack anymore as I understand.

    C:\GitHub\tmp>mkdir tmp-does-next-have-webpack
    
    C:\GitHub\tmp>cd tmp-does-next-have-webpack
    
    C:\GitHub\tmp\tmp-does-next-have-webpack>npm install next
    
    added 30 packages in 8s
    
    5 packages are looking for funding
      run `npm fund` for details
    
    C:\GitHub\tmp\tmp-does-next-have-webpack>npm ls next
    tmp-does-next-have-webpack@ C:\GitHub\tmp\tmp-does-next-have-webpack
    `-- [email protected]
    
    
    C:\GitHub\tmp\tmp-does-next-have-webpack>npm ls webpack
    tmp-does-next-have-webpack@ C:\GitHub\tmp\tmp-does-next-have-webpack
    `-- (empty)
    
    
    C:\GitHub\tmp\tmp-does-next-have-webpack>
    

    Regarding the proposed solution: Totally understand implications on your end and why having // @ts-ignore might not work for you without further pre- or post-processing or some other solution.

    Regarding the problem statement: It is probably rare for people to disable skipLibCheck. Totally understand why you haven't heard about it before.

    Regarding our personal needs: We've solved the issue on our end with patch-package for now.

    The root need,

    The reason we name our internal files .d.ts instead of .ts is not to export them, but just to provide clarity to the broader team that there is no runtime code in those files.

    and the disabling of skipLibCheck was known to have such a tradeoff somewhere. :)

  10. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 28, 2024
  11. Lms24 commented on Oct 29, 2024

    @Lms24
    Member

    Thanks for the detailed explanation! i can't promise we'll change something but before we close this issue, I will tag @lforst: We could think about vendoring in the imported types to get rid of the webpack type imports. If webpack isn't always available in NextJS this might become problematic in more ways. Another option would be to add it as a dep to our package but this seems a bit over the top... wdyt?

  12. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 29, 2024
  13. lforst commented on Oct 29, 2024

    @lforst
    Contributor

    Oh yeah thanks for roping me in. Two things:

    • Next.js is definitely still using webpack.
    • We are definitely leaking crappy types into our type exports.

    Opened a PR to fix #14116

  14. github-actions commented on Oct 31, 2024

    @github-actions
    Contributor

    A PR closing this issue has just been released 🚀

    This issue was referenced by PR #14116, which was included in the 8.36.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions