Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Cannot find module 'ws' means Node.js code tried to load the ws package but could not resolve it from that code’s runtime context. Find the importing file in the error’s require stack first. If your application code imports ws, install it as a runtime dependency of the package that owns that code. If development works but the packaged Electron app fails, check whether the built application includes the dependency. If the import is in browser code, use the browser’s native WebSocket API instead: the ws package is for Node.js, not browsers.

What the error means—and what it does not tell you

The error identifies a failed module lookup, not its cause. The package may be absent, declared in a different workspace, omitted from a packaged application, or requested from a browser bundle where Node’s module resolution does not apply. The error message alone does not distinguish among those cases.

ws is a Node.js WebSocket client/server package. It is not the browser’s built-in WebSocket API, and its maintainers state that it does not work in browsers. Playwright’s WebSocket inspection and testing features are separate from whether your application or one of its dependencies can resolve the Node package. Using Playwright does not automatically add ws to every project that uses it.

Likewise, Electron’s documented net.WebSocket is a separate option available in the main process. It uses Chromium’s network stack, but it is not established as a drop-in replacement for every ws API or for a dependency that explicitly imports ws.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Start with the require stack

Read the full error, including the require stack (the list of files involved in the failed load). Note where the failure occurs: in Electron’s main process, a renderer, a Playwright test runner, or the packaged application. Then identify the first relevant file in the stack that requests ws.

  • Your code imports it: Look for calls such as require('ws') or import WebSocket from 'ws'. The application package containing that code should declare ws as a runtime dependency.
  • Another package imports it: The stack points into a dependency rather than your own source. Check that package’s dependency declaration and the installation tree. Don’t assume that adding an unrelated direct dependency is the right fix; first determine which package is requesting it.
  • The stack points to browser code: Check whether a renderer or browser-targeted bundle is trying to use the Node package. Browser code that needs WebSockets should generally use the browser’s native API.
  • It fails only after packaging: Compare the working development runtime with the built application. A dependency available in the development installation may not have made it into the artifact.

Install ws when your Node.js code imports it

Install the package in the application package that owns the importing code, using the package manager and workspace context your project already uses. The package’s documented npm command is:

npm install ws

For application code that needs ws at runtime, it belongs in that application’s runtime dependencies, not only among development-only tools. After installation, inspect the owning package’s manifest and lockfile to confirm the dependency was recorded in the right place. A successful install from a different directory in a monorepo does not, by itself, establish that the failing package can resolve it.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

For example, if the error names apps/desktop/src/socket.js, inspect the package configuration that governs apps/desktop and the workspace rules in use. Do not copy a workspace-specific command from another project: npm, Yarn, pnpm, and repository layouts can differ. Use the repository’s own package-manager configuration and install from the appropriate workspace root or package directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Then check resolution from the same package and runtime context that failed. A basic Node check is:

node -e "console.log(require.resolve('ws'))"

Run it where the application code is resolved, not merely from a convenient repository directory. If your code uses ECMAScript modules, this command still checks Node’s package resolution, but it does not reproduce every bundler or packaged-runtime condition. A passing check narrows the problem; it does not prove the packaged Electron artifact contains the module.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Fix a missing dependency in Playwright projects

First establish which process imports ws. A Playwright test, a Node.js helper used by the test, an application server, and the page running in a browser are different contexts. If a test helper or server imports ws directly, install it as a runtime dependency of the package that runs that Node.js code. If the require stack points into a separate dependency, inspect that package and your installed dependency tree.

Playwright documents WebSocket observation and related testing capabilities. Those features can help you inspect traffic or test application behavior; they do not replace a Node dependency required by your own code or another package. Conversely, browser page code should not import the Node-only ws package just because the test suite is written with Playwright. Use the page’s browser WebSocket API for browser-side connections.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the failure occurs only when Playwright runs tests, compare the test command’s working directory, environment, and package resolution with the context where the application works. Check the require stack from the failing run rather than relying on a successful install or import check performed in another package.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Fix an Electron error that happens only in the packaged app

A common symptom pattern is that Electron works during development but reports Cannot find module 'ws' after packaging, sometimes with a path under app.asar. That pattern is a clue to inspect the artifact; it does not prove that a particular packager has a universal ws defect or that one specific setting will fix every project.

  1. Confirm the failing runtime. Reproduce the error in the packaged build and capture the full stack. Identify whether the importing code runs in the main process or another runtime.
  2. Confirm dependency ownership. Make sure the package containing the importing Node.js code declares ws as a runtime dependency. Check whether production dependency pruning or workspace configuration changes what is installed for the build.
  3. Inspect the built application. Check the packaged resources and the packager’s inclusion, exclusion, and externalization configuration to see whether the required dependency is present in the form the runtime expects.
  4. Correct the project-specific build configuration. Don’t add a generic archive or “unpack” setting just because the error mentions app.asar. The appropriate configuration depends on the packager, its version, and how the application bundles dependencies.
  5. Rebuild and retest the artifact. Verify the same packaged runtime that failed. A working development run or a passing local resolution check is not confirmation that the packaged application is fixed.

An individual Electron report describes this development-versus-packaged failure, but it is an example of the symptom rather than an authoritative configuration recipe. Treat the require stack and the contents of your own build as the evidence for your fix.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decide whether to use a different WebSocket API

Replacing ws is a design choice, not a general module-resolution fix. Use the runtime and API that fit the code making the connection:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Where the code runs What to consider Important limit
Node.js application code that imports ws Install ws in the owning runtime package and ensure it is available in the failing environment. Another API does not satisfy a package’s explicit ws import unless that package or its code is changed.
Browser page or renderer code Use the browser’s native WebSocket API when it fits the requirement. The ws project says its package does not work in browsers.
Electron main process Evaluate Electron’s documented net.WebSocket API if its behavior and supported runtime fit the use case. It is a separate API, not proven here to be compatible with every ws interface or dependency.
Playwright network inspection or tests Use Playwright’s documented WebSocket capabilities for the inspection or testing task. Those capabilities do not remove separate runtime dependencies from application code.

For remote connections in Electron, security guidance recommends secure transport such as WSS rather than WS. That is a transport-security decision; it does not resolve a missing-module error.

Troubleshoot by symptom

  • “It’s installed, but Node still cannot find it.” Verify the import’s owning package and run the resolution check from that package’s context. In a workspace, inspect which manifest and installation layout apply there.
  • The require stack points to a third-party package. Check that package’s declared dependencies and the installed tree. Determine whether its installation is incomplete or whether your build has excluded a runtime dependency before changing application code.
  • Development works; the packaged app fails. Inspect runtime dependency inclusion, production pruning, exclusions, and externalization in the actual build configuration. Rebuild and test the packaged artifact after the change.
  • The failing code is in a renderer or browser bundle. Confirm whether the code should use the browser’s native WebSocket API. Installing the Node package does not make it a browser implementation.
  • You are considering optional WebSocket add-ons. The ws package documents bufferutil and utf-8-validate as optional performance-related modules in relevant environments. They are not substitutes for the missing ws package and are not the first fix for this error.
  • The error disappears locally but remains in CI or on another machine. Compare the dependency manifest, lockfile, install mode, workspace context, and build artifact used in each environment. Establish that the same runtime package is being installed and packaged before attributing the difference to the WebSocket connection itself.

Performance, reliability, and version notes

Resolve the missing module before investigating connection performance: a module lookup failure occurs before the application can use the package for its WebSocket work. The optional ws add-ons are performance-related, but adding them will not repair a missing core dependency.

Choose a package version based on your project’s compatibility and security requirements rather than copying a registry version number from an old page. A registry snapshot reported ws version 8.22.0 at one point; that is a time-sensitive snapshot, not a recommendation to pin that version. Check the current package metadata and your project’s supported Node.js and Electron versions when selecting a release.

The reliable confirmation is a retest of the exact execution path that failed: the Playwright test process, Electron development runtime, or packaged application. No single successful check covers all three.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If your Electron or Playwright work also needs website screenshots, ScreenshotNeo offers a screenshot API and MCP server. This is a separate option for capturing pages, not a fix for a missing ws dependency. The API accepts one GET request; see the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie or consent banners, newsletter popups, and chat widgets are removed before capture; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed. Responses identify the page verdict and billing status in headers.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents, including Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.