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

esnext problem #160

Closed
basz opened this issue May 27, 2024 · 7 comments
Closed

esnext problem #160

basz opened this issue May 27, 2024 · 7 comments

Comments

@basz
Copy link
Contributor

basz commented May 27, 2024

the changed esnext compile thing from 1.11.0 is breaking usage for me in an EmberJS app

websocket.browser.js:75 Uncaught (in promise) ReferenceError: exports is not defined
    at eval (websocket.browser.js:75:1)
    at ../../../../../node_modules/.pnpm/[email protected]/node_modules/rpc-websockets/dist/lib/client/websocket.browser.js (chunk.8496e8a15f9678fec839.js:14589:1)
    at __webpack_require__ (chunk.3416202bc0ec78d6e0f4.js:31:42)
    at eval (index.browser.js:12:45)
    at ../../../../../node_modules/.pnpm/[email protected]/node_modules/rpc-websockets/dist/index.browser.js (chunk.8496e8a15f9678fec839.js:14567:1)
    at __webpack_require__ (chunk.3416202bc0ec78d6e0f4.js:31:42)
    at eval (socket.actions.js:8:26)
    at ../../../../../packages/@3dlayermaker-common/dist/moonraker/socket.actions.js (chunk.17f662c24397a7eb1ab4.js:1567:1)
    at __webpack_require__ (chunk.3416202bc0ec78d6e0f4.js:31:42)
    at eval (index.js:26:14)

That file ends up as (indeed without exports)

Object.defineProperty(__webpack_exports__, "__esModule", ({
  value: true
}));
const eventemitter3_1 = __webpack_require__(/*! eventemitter3 */ "../../../../../node_modules/.pnpm/[email protected]/node_modules/eventemitter3/index.js");
class WebSocketBrowserImpl extends eventemitter3_1.EventEmitter {
  /** Instantiate a WebSocket class
   * @constructor
   * @param {String} address - url to a websocket server
   * @param {(Object)} options - websocket options
   * @param {(String|Array)} protocols - a list of protocols
   * @return {WebSocketBrowserImpl} - returns a WebSocket instance
   */
  constructor(address, options, protocols) {
    super();
    (0,_Users_bas_Documents_Projects_iSole3D_3DLayerMaker_repositories_3DLayerMaker_Dashboard_node_modules_pnpm_babel_runtime_7_23_9_node_modules_babel_runtime_helpers_esm_defineProperty_js__WEBPACK_IMPORTED_MODULE_0__["default"])(this, "socket", void 0);
    this.socket = new window.WebSocket(address, protocols);
    this.socket.onopen = () => this.emit("open");
    this.socket.onmessage = event => this.emit("message", event.data);
    this.socket.onerror = error => this.emit("error", error);
    this.socket.onclose = event => {
      this.emit("close", event.code, event.reason);
    };
  }
  /**
   * Sends data through a websocket connection
   * @method
   * @param {(String|Object)} data - data to be sent via websocket
   * @param {Object} optionsOrCallback - ws options
   * @param {Function} callback - a callback called once the data is sent
   * @return {Undefined}
   */
  send(data, optionsOrCallback, callback) {
    const cb = callback || optionsOrCallback;
    try {
      this.socket.send(data);
      cb();
    } catch (error) {
      cb(error);
    }
  }
  /**
   * Closes an underlying socket
   * @method
   * @param {Number} code - status code explaining why the connection is being closed
   * @param {String} reason - a description why the connection is closing
   * @return {Undefined}
   * @throws {Error}
   */
  close(code, reason) {
    this.socket.close(code, reason);
  }
  addEventListener(type, listener, options) {
    this.socket.addEventListener(type, listener, options);
  }
}
/**
 * factory method for common WebSocket instance
 * @method
 * @param {String} address - url to a websocket server
 * @param {(Object)} options - websocket options
 * @return {Undefined}
 */
function default_1(address, options) {
  return new WebSocketBrowserImpl(address, options);
}
exports.default = default_1;

Probably an config thing but if anyone sees what it could be please let me know

@mkozjak
Copy link
Member

mkozjak commented May 28, 2024

@steveluscher

@steveluscher
Copy link
Contributor

Can you throw up a repro repository or Codesandbox? I’ll debug it.

@basz
Copy link
Contributor Author

basz commented May 29, 2024

that would be really appreciated https://github.com/basz/rpc-test

@NullVoxPopuli
Copy link

exports doesn't exist in the browser.

Can this be distributed as ESM?

@steveluscher
Copy link
Contributor

I tried your repro, and unfortunately couldn't break it.

sudo n lts  # Install Node LTS
rm pnpm-lock.yaml  # Your lockfile was giving me trouble
pnpm i
pnpm start:dev
image image

@basz
Copy link
Contributor Author

basz commented Jun 1, 2024 via email

@steveluscher
Copy link
Contributor

The solution was the most annoying thing possible.

Rename everything to .cjs.

#161.

@mkozjak mkozjak closed this as completed Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants