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
When trying to load the library using and running the script in esm mode:
import{Client}from'faye-websocket';
I got an error:
SyntaxError: Named export 'Client' not found. The requested module 'faye-websocket' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'faye-websocket';
const { Client } = pkg;
It suggests a workaround by using the default import first, then destruct the import, but it would be nice for the library to provide an esm entry point using the exports field.
The text was updated successfully, but these errors were encountered:
CommonJS modules can be imported from ESM modules using the import keyword. As you've noticed, you cannot "destructure" the module in the import statement, because it's not an ESM module, but import WebSocket from 'faye-websocket' should work and let you access everything else the package exports via the WebSocket binding.
I currently have no plans to add ESM support to my packages because, having tried it out, my impression is that it adds a substantial amount of complexity for packages to support both kinds of exports, in terms of building, testing and publishing the package. Given that CommonJS can be imported from ESM, I'm not convinced that complexity is worth it.
When trying to load the library using and running the script in esm mode:
I got an error:
It suggests a workaround by using the default import first, then destruct the import, but it would be nice for the library to provide an esm entry point using the exports field.
The text was updated successfully, but these errors were encountered: