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.

Useless exports, and broken IIFE

See original GitHub issue
  • Echo Version: 1.12.0
  • Laravel Version: 9.18.0
  • PHP Version: 8.1.7
  • NPM Version: 8.11.0
  • Node Version: 16.15.1

Description:

In v1.11.5 the IIFE distribution file was broken by https://github.com/laravel/echo/pull/333. In my opinion, the new exports are completely useless given classes are already exported in their own right:

They can be used without modification to the library, by simply:

import { PresenceChannel } from 'laravel-echo/src/channel'

The changes break the IIFE distribution by exporting multiple objects. The change results in new usage:

var myEcho = new Echo.default({});

This was highlighted in https://github.com/laravel/echo/issues/336 already, but closed as unsupported. If that’s the case, then I would suggest that the IIFE distribution is removed. However, that seems unnecessary given the changes in https://github.com/laravel/echo/pull/333 are unnecessary and if they were to be reverted then the IIFE distribution would work again…

Steps To Reproduce:

Use the dist/echo.iife.js file:

<script src="echo.iife.js"></script>
<script>var myEcho = new Echo({});</script>
Uncaught TypeError: Echo is not a constructor

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bytestreamcommented, Jun 29, 2022

Thanks for looking into this @jessarcher ☺️

importing the classes from laravel-echo/src/* seems a bit clunky. I’d prefer the packaged version to exclude the src directory, https://github.com/laravel/echo/pull/92, to save space and bandwidth

I disagree with this. I, for example, use the src classes to extend the library https://github.com/supportpal/pollcast-js/blob/master/src/broadcasting/channels/channel.ts. Bandwidth would only really be saved in pulls from npm. Users shouldn’t be shipping node_modules, but using something like webpack

You’ve mentioned removing the IIFE build, but as far as I can tell, IIFE still works - it’s just the usage that has unfortunately changed.

Correct

See: https://github.com/laravel/echo/pull/344

Thanks @timacdonald !

0reactions
timacdonaldcommented, Jun 29, 2022

No troubles at all ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Modules: From IIFEs to CommonJS to ES6 ... - ui.dev
Exports are the "interface" to the module. Whatever you export from a module will be available to whoever imports that module. Enough with...
Read more >
Additional parameters for IIFE output #1962 - rollup ... - GitHub
I can choose from having the immediate function passed jQuery (correct) or $ (wrong) but the function parameter is always named jQuery (useless) ......
Read more >
How do i export an es6 IIFE? - javascript - Stack Overflow
Since you want a default export, you can put the whole thing after an export default . Since you also want to be...
Read more >
What Is Comparative Advantage? Definition Vs. Absolute ...
Comparative advantage suggests that countries will engage in trade with one another, exporting the goods that they have a relative advantage in. Absolute ......
Read more >
The U.S. Trade Deficit: How Much Does It Matter?
A trade deficit occurs when a nation imports more than it exports. ... slapping high tariffs on Chinese goods, would likely be ineffective,...
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