transloadit / uppy

The next open source file uploader for web browsers :dog:
https://uppy.io
MIT License
28.57k stars 1.96k forks source link

Errors in TypeScript definitions when installed with pnpm #5164

Open andersk opened 1 month ago

andersk commented 1 month ago

Initial checklist

Link to runnable example

No response

Steps to reproduce

From an empty directory:

$ pnpm i @uppy/core typescript
Packages: +11
+++++++++++
Progress: resolved 11, reused 11, downloaded 0, added 11, done

dependencies:
+ @uppy/core 3.11.3
+ typescript 5.4.5

Done in 1.2s

$ echo 'import "@uppy/core"' > test.ts

$ pnpm exec tsc test.ts

Expected behavior

No errors.

Actual behavior

Several errors:

node_modules/.pnpm/@uppy+core@3.11.3/node_modules/@uppy/utils/types/index.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: Translator, EventManager, ProgressTimeout, internalRateLimitedQueue, canvasToBlob, dataURItoBlob, dataURItoFile, emitSocketProgress, findAllDOMElements, findDOMElement, generateFileID, getBytesRemaining, getETA, getFileNameAndExtension, getFileType, getFileTypeExtension, getSocketHost, getSpeed, getTimeStamp, isDOMElement, isObjectURL, isDragDropSupported, isPreviewSupported, isTouchDevice, prettyETA, secondsToTime, settle, toArray, AbortController, AbortSignal, getDroppedFiles, getTextDirection, NetworkError, exports, ErrorWithCause, InternalMetadata

1 declare module '@uppy/utils/lib/Translator' {
  ~~~~~~~

  node_modules/.pnpm/@uppy+utils@5.9.0/node_modules/@uppy/utils/types/index.d.ts:1:1
    1 declare module '@uppy/utils/lib/Translator' {
      ~~~~~~~
    Conflicts are in this file.

node_modules/.pnpm/@uppy+core@3.11.3/node_modules/@uppy/utils/types/index.d.ts:349:5 - error TS2374: Duplicate index signature for type 'string'.

349     [key: string]: T
        ~~~~~~~~~~~~~~~~

node_modules/.pnpm/@uppy+core@3.11.3/node_modules/@uppy/utils/types/index.d.ts:350:5 - error TS2374: Duplicate index signature for type 'number'.

350     [key: number]: T
        ~~~~~~~~~~~~~~~~

node_modules/.pnpm/@uppy+utils@5.9.0/node_modules/@uppy/utils/types/index.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: Translator, EventManager, ProgressTimeout, internalRateLimitedQueue, canvasToBlob, dataURItoBlob, dataURItoFile, emitSocketProgress, findAllDOMElements, findDOMElement, generateFileID, getBytesRemaining, getETA, getFileNameAndExtension, getFileType, getFileTypeExtension, getSocketHost, getSpeed, getTimeStamp, isDOMElement, isObjectURL, isDragDropSupported, isPreviewSupported, isTouchDevice, prettyETA, secondsToTime, settle, toArray, AbortController, AbortSignal, getDroppedFiles, getTextDirection, NetworkError, exports, ErrorWithCause, InternalMetadata

1 declare module '@uppy/utils/lib/Translator' {
  ~~~~~~~

  node_modules/.pnpm/@uppy+core@3.11.3/node_modules/@uppy/utils/types/index.d.ts:1:1
    1 declare module '@uppy/utils/lib/Translator' {
      ~~~~~~~
    Conflicts are in this file.

node_modules/.pnpm/@uppy+utils@5.9.0/node_modules/@uppy/utils/types/index.d.ts:54:13 - error TS2649: Cannot augment module 'RateLimitedQueue' with value exports because it resolves to a non-module entity.

54   namespace RateLimitedQueue {
               ~~~~~~~~~~~~~~~~

node_modules/.pnpm/@uppy+utils@5.9.0/node_modules/@uppy/utils/types/index.d.ts:349:5 - error TS2374: Duplicate index signature for type 'string'.

349     [key: string]: T
        ~~~~~~~~~~~~~~~~

node_modules/.pnpm/@uppy+utils@5.9.0/node_modules/@uppy/utils/types/index.d.ts:350:5 - error TS2374: Duplicate index signature for type 'number'.

350     [key: number]: T
        ~~~~~~~~~~~~~~~~

Found 7 errors in 2 files.

Errors  Files
     3  node_modules/.pnpm/@uppy+core@3.11.3/node_modules/@uppy/utils/types/index.d.ts:1
     4  node_modules/.pnpm/@uppy+utils@5.9.0/node_modules/@uppy/utils/types/index.d.ts:1
mifi commented 1 month ago

are you saying the same works with npm or yarn? that means that pnpm is doing something differently with the node_modules file structure (?)

mifi commented 1 month ago

hmm, it seems to be installing the modules inside node_modules/.pnpm/package_name instead of the normal node_modules/package_name

aduh95 commented 1 month ago

@mifi it's unrelated to pnpm, the error reported are in the index.d.ts file.

@andersk interesting, it looks like those have been here for a long time and never were reported/noticed 🤔 FWIW we already have removed that file in the 4.x beta line, if you try with @uppy/core@next, you should not see those errors.

aduh95 commented 1 month ago

To confirm, I was able to get rid of the error with the following:

$ pnpm i @uppy/core@next
Packages: +4 -4
++++----
Progress: resolved 11, reused 7, downloaded 4, added 4, done

dependencies:
- @uppy/core 3.11.3
+ @uppy/core 4.0.0-beta.7

Done in 3.6s
$ pnpm exec tsc --target es6 test.ts

One of the changes we made in the 4.x branch was to switch our source files to TS, as the manually curated .d.ts files was more likely to have mistakes in them. I'm not sure fixing given how close we are from releasing the 4.x branch.

Murderlon commented 1 month ago

3.x should be in a good state for quite a while still as the vast majority of people are on it and will stay on it. Therefor I think we should fix it.