question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not find a declaration file for module 'ws'

See original GitHub issue

I have a vanilla project setup:

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "graphql-yoga": "^1.14.8"
  },
  "devDependencies": {
    "@types/node": "10.1.2",
    "typescript": "^2.9.2"
  }
}

{
  "compilerOptions": {
    "strict": true,
    "noImplicitReturns": true,
    "esModuleInterop": true,
    "module": "commonjs",
    "target": "es2015",
    "sourceMap": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "lib": [
      "es2015",
      "esnext.asynciterable"
    ]
  },
  "include": ["./*.ts"]
}
import { GraphQLServer } from "graphql-yoga";

const typeDefs = `
Query {
  hello(name: String): String!
}
`

const resolvers = {
  Query: {
    hello: () => {
      return ""
    },
  },
}

const server = new GraphQLServer({ typeDefs, resolvers })

server.start().then(server => {
  console.log("started server at %s", server.address())
})

❯ yarn -s tsc --project tsconfig.json
node_modules/subscriptions-transport-ws/dist/server.d.ts:2:28 - error TS7016: Could not find a declaration file for module 'ws'. '/Users/jasonkuhrt/projects/personal/test/node_modules/ws/index.js' implicitly has an 'any' type.
  Try `npm install @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`

2 import * as WebSocket from 'ws';
                             ~~~~


error Command failed with exit code 2.

I realize this might be an upstream issue. Anyone else hitting this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
joe-recommented, Jun 20, 2018

I encountered the same issue. You’ll be able to fix it getting ws module type definition by manually.

yarn add @types/ws -D
1reaction
salviosagecommented, Jan 16, 2021

Hey @rohmanhm , can you try add this in your typescript configuration file. "noImplicitAny": false

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not find a declaration file for module 'module-name ...
In order for this to work, I had to make declare module '...' the first line of code in the module.d.ts file, and...
Read more >
Could not find declaration file for module 'X' Error | bobbyhadz
The error "Could not find a declaration file for module" occurs when TypeScript cannot find the type declaration for a module. To solve...
Read more >
How to fix error TS7016: Could not find a declaration file for ...
Try `npm install @types/XYZ` if it exists or add a new declaration (.d. · declare module 'XYZ';. Lastly, you also need to add...
Read more >
Error: Could not find a declaration file for module - YouTube
Fix error: Could not find a declaration file for module ... implicitly has an 'any' type.Try npm install library-name if it exists or...
Read more >
Fixing the TS7016 Error | Atomist Blog
4 Terrible Ways (and 4 Better Ways) to fix 'TS7016: Could not find declaration file' · Caveat: the compiler option --noEmitOnError makes ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found