You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've searched for any related issues and avoided creating a duplicate issue.
Description
Hello, I maintain a library which can be used either in the browser or in Node apps. Our code has a simple environment detection and we conditionally require 'ws'. This used to work great prior to WS 8, because the "browser" field in the package.json made sure that when this lib is being bundled for the browser, the ws lib will effectively return a noop.
We upgraded to ws@8.12.0 and clients started reporting issues building their React apps with our lib. We traced the issue down to the ws lib, which did not fallback to a noop. The reason for this is the included "exports" property:
Exports has priority over "main" and over "browser", which effectively means that the "browser" field is ignored, resulting in errors like "Module not found: Error: Can't resolve 'stream' in '/Users/flash/Coding/temp/react-empty/node_modules/ws/lib'"
A simple solution is to add "browser" to the "exports" field like this:
Is there an existing issue for this?
Description
Hello, I maintain a library which can be used either in the browser or in Node apps. Our code has a simple environment detection and we conditionally require 'ws'. This used to work great prior to WS 8, because the "browser" field in the package.json made sure that when this lib is being bundled for the browser, the ws lib will effectively return a noop.
example snippet for ws@7.5.9 package.json:
We upgraded to ws@8.12.0 and clients started reporting issues building their React apps with our lib. We traced the issue down to the ws lib, which did not fallback to a noop. The reason for this is the included "exports" property:
example snippet for ws@8.12.0 package.json:
Exports has priority over "main" and over "browser", which effectively means that the "browser" field is ignored, resulting in errors like "Module not found: Error: Can't resolve 'stream' in '/Users/flash/Coding/temp/react-empty/node_modules/ws/lib'"
A simple solution is to add "browser" to the "exports" field like this:
This way bundling ws for the browser will continue to work as pre 8.
ws version
8.12.0
Node.js Version
18.13.0
System
System:
OS: macOS 13.2
CPU: (8) arm64 Apple M1 Pro
Memory: 775.80 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Expected result
I expect that ws would not break the webpack bundling for the browser.
Actual result
Attempting to bundle ws with webpack results in error:
Module not found: Error: Can't resolve 'stream' in '/Users/flash/Coding/temp/react-empty/node_modules/ws/lib'
Did you mean './stream'?
Attachments
No response
The text was updated successfully, but these errors were encountered: