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

Ignoring node_modules #45

Closed
whs opened this issue Oct 15, 2019 · 17 comments · Fixed by #110
Closed

Ignoring node_modules #45

whs opened this issue Oct 15, 2019 · 17 comments · Fixed by #110
Labels
bug Something isn't working

Comments

@whs
Copy link

whs commented Oct 15, 2019

Apologies for using issue as a support ticket.

I found that tsd ventures into node_modules and throw error from other modules:

> tsd


  node_modules/@types/node/index.d.ts:78:10
  ✖  78:10  Duplicate identifier IteratorResult.  

  node_modules/tsd/libraries/typescript/lib/lib.es2015.iterable.d.ts:41:5
  ✖  41:5   Duplicate identifier IteratorResult.  

  2 errors

Is there anyway I could fix this? Ideally, without moving the types into subdirectory. (Right now the types is at repository root)

@TehShrike
Copy link

The errors above happened when @types/node@8.10 is in node_modules:

├─┬ tape-run@4.0.0
│ └─┬ browser-run@4.1.3
│   └─┬ electron-stream@5.1.2
│     └─┬ electron@1.8.8
│       └── @types/node@8.10.38  deduped
└─┬ tsd@0.9.0
  └─┬ globby@9.2.0
    └─┬ @types/glob@7.1.1
      └── @types/node@8.10.38 

Once I updated the dependencies in that project to not have any versions of @types/node older than 10.14, tsd ran successfully.

@SamVerschueren
Copy link
Collaborator

It's weird because I looked into this and tsd definitely does not glob inside node_modules.

@SamVerschueren
Copy link
Collaborator

Okay, I see what the problem is. I ship TypeScript myself because I need to expose 2 private methods (which are really needed). But it looks like it colissions with node types. Have to investigate this further. Thanks for the report!

@likern
Copy link

likern commented Dec 26, 2019

@SamVerschueren is there a workaround to exclude node_modules?

@mskelton
Copy link

mskelton commented Feb 4, 2020

@SamVerschueren Any progress on this?

@fregante
Copy link

fregante commented Feb 5, 2020

My guess is that Typescript still loads types in @types so they need to be "valid" somehow. In my case, adding a lib to tsconfig.json "fixed it" for me. I had these errors:

  index.ts:128:2
  ✖   128:2    Cannot find name window.
  node_modules/@types/filesystem/index.d.ts:355:11
  ✖   355:11   Cannot find name File.
  ✖   369:10   Cannot find name DOMError.
  ✖   541:12   Cannot find name File.
  node_modules/@types/filewriter/index.d.ts:10:28
  ✖    10:28   Cannot find name EventTarget.
  ✖    64:26   Cannot find name ProgressEvent.
  ✖    69:24   Cannot find name ProgressEvent.
  ✖    74:21   Cannot find name ProgressEvent.
  ✖    79:21   Cannot find name ProgressEvent.
  ✖    84:21   Cannot find name ProgressEvent.
  ✖    89:24   Cannot find name ProgressEvent.
  ✖    97:13   Cannot find name Blob.
  ✖   119:15   Cannot find name Blob.
  ✖   153:15   Cannot find name Blob.
  node_modules/@types/chrome/index.d.ts:482:20
  ✖   482:20   Cannot find name ImageData.
  ✖   482:51   Cannot find name ImageData.
  ✖  2460:22   Cannot find name SubtleCrypto.
  ✖  4725:20   Cannot find name ImageData.
  ✖  4725:51   Cannot find name ImageData.
  ✖  4892:22   Cannot find name KeyAlgorithm.
  ✖  4947:99   Cannot find name CryptoKey.
  ✖  4947:122  Cannot find name CryptoKey.
  ✖  4949:36   Cannot find name SubtleCrypto.
  ✖  5006:18   Cannot find name Blob.
  ✖  6886:27   Cannot find name MediaStreamConstraints.
  ✖  6888:27   Cannot find name MediaStreamConstraints.
  ✖  6898:72   Cannot find name MediaStream.
  27 errors

peterMuriuki added a commit to onaio/reveal-frontend that referenced this issue Apr 14, 2020
Reason: seems the minor versions in v7 do not respect semver rules
There is a breaking change in terms of the exposed interface between
minor versions 7.0.8 and 7.1.7. Specifically the ConnectedComponentClass
type is not exported in 7.1.7. ConnectedComponentClass is used by
onaio/js-tools.

as a result tsd complains that the above type is not present
in node_modules @types/react-redux, which in itself is another
problem since tsd should not be evaluating types in node_modules,
apparently there has been an issue raised for this and its unfortunately
something we cannot fix from here. for Reference:
tsdjs/tsd#45
peterMuriuki added a commit to onaio/reveal-frontend that referenced this issue Apr 14, 2020
Reason: seems the minor versions in v7 do not respect semver rules
There is a breaking change in terms of the exposed interface between
minor versions 7.0.8 and 7.1.7. Specifically the ConnectedComponentClass
type is not exported in 7.1.7. ConnectedComponentClass is used by
onaio/js-tools.

as a result tsd complains that the above type is not present
in node_modules @types/react-redux, which in itself is another
problem since tsd should not be evaluating types in node_modules,
apparently there has been an issue raised for this and its unfortunately
something we cannot fix from here. for Reference:
tsdjs/tsd#45
@alexboffey
Copy link

Can confirm @fregante 's solution works 🙏

Added this to package.json:

  "tsd": {
    "compilerOptions": {
      "lib": [
        "DOM"
      ]
    }
  }

@SamVerschueren
Copy link
Collaborator

Not immediately an out of the box solution yet though. Sorry about this.

@SamVerschueren
Copy link
Collaborator

I wanted to look into this again, but can't seem to reproduce this. Does someone have a minimal example on how I can trigger this behaviour?

@fregante
Copy link

fregante commented Jul 4, 2020

I have another guess for why this happens: I think last time I had this issue was because the d.ts file was not actually listed in tsconfig, so I think typescript tried automatically looking for files, including node_modules in the process.

@admataz
Copy link

admataz commented Jul 6, 2020

@SamVerschueren - we are seeing fails here - which I think is caused by this issue. Just diving into it now.
fastify/fastify-basic-auth#18

@admataz
Copy link

admataz commented Jul 6, 2020

Follow up - it looks like the fail in the above instance is from an underlying upgrade to globby which removed a dependency on @types/glob, which in turn, had included @types/node.

With @types/node no longer in our node_modules via this dependency chain, ts errors are thrown when we run tsd tests.

My question at this point - should we be explicitly including @types/node in our projects - or is this something we should expect to be part of tsd ?

@wooorm
Copy link

wooorm commented Nov 5, 2020

Getting this today, but for things unrelated to node or browsers:

> tsd
  node_modules/@types/eslint/index.d.ts:260:40
  ✖  260:40  Namespace "/Users/tilde/Projects/oss/micromark/node_modules/@types/estree/index" has no exported member ChainExpression.   
  ✖  283:41  Namespace "/Users/tilde/Projects/oss/micromark/node_modules/@types/estree/index" has no exported member ImportExpression.  

(dtslint has the same problem btw)

@pamls
Copy link

pamls commented Dec 4, 2020

@wooorm have you found a solution?

@wooorm
Copy link

wooorm commented Dec 4, 2020

micromark/micromark@c78c1c2 worked for us

@fregante
Copy link

@BendingBender
Copy link
Collaborator

BendingBender commented May 29, 2021

@whs @TehShrike @likern @mskelton @fregante @p-netm @alexboffey @admataz @wooorm @pamls @derhuerst @belozer

Would you mind testing my branch (https://github.com/BendingBender/tsd/tree/ignore-errors-from-node-modules) and reporting whether it fixes the problem for you? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.