Skip to content

Conversation

@xchellx
Copy link

@xchellx xchellx commented May 28, 2022

This gives compatibility for browsers by adding on to the window object
if define and module.exports isn't available.

This gives compatibility for browsers by adding on to the window object
if `define` and `module.exports` isn't available.
@nikelborm
Copy link

@inolen please 🙏🏻🙏🏻 👉🏻👈🏻 🥺🥺

@nikelborm
Copy link

nikelborm commented Dec 22, 2025

If anybody needs this, I've published a version with this fix

https://www.npmjs.com/package/@nikelborm/bit-buffer/v/0.3.0

@inolen
Copy link
Owner

inolen commented Dec 22, 2025

Sorry, but why is this needed? Can't you just import it as an es6 module vs merging with the window object?

@nikelborm
Copy link

nikelborm commented Dec 22, 2025

Sorry, but why is this needed? Can't you just import it as an ES6 module vs merging with the window object?

It's impossible to import it because you don't export it as an ES module.

I had to create a new file that exports your 2 classes and removes the IIFE for that. I added the export keyword before classes.

Check bit-buffer.mjs here.
https://www.npmjs.com/package/@nikelborm/bit-buffer/v/0.3.1?activeTab=code

@nikelborm
Copy link

nikelborm commented Dec 22, 2025

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Demo</title>
    <script type="importmap">
      {
        "imports": {
          "bit-buffer": "https://cdn.jsdelivr.net/npm/bit-buffer@0.3.0/+esm",
          "@nikelborm/bit-buffer": "https://cdn.jsdelivr.net/npm/@nikelborm/bit-buffer@0.3.1/+esm"
        }
      }
    </script>
    <script type="module">
      import { BitView } from '@nikelborm/bit-buffer';
      console.log('BitView from nikelborm', BitView);
    </script>
    <script type="module">
      import { BitView } from 'bit-buffer';
    </script>
  </head>
  <body></body>
</html>

Repro

@nikelborm
Copy link

image

@nikelborm
Copy link

nikelborm commented Dec 22, 2025

I initially wanted this PR to be merged because it was already there, and I wouldn't have to do any work.

Then I decided that I can't wait for this to be landed and published @nikelborm/bit-buffer@0.3.0, which has the fix from PR applied.

However, since I was already in this rabbit hole, I realized that implementing it with ESM would be a better idea, so I republished it with proper ESM syntax in @nikelborm/bit-buffer@0.3.1.

@inolen
Copy link
Owner

inolen commented Dec 22, 2025 via email

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

Successfully merging this pull request may close these issues.

3 participants