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

The js_cols dependency breaks modern setups #3

Open
bwswedberg opened this issue Mar 18, 2024 · 0 comments
Open

The js_cols dependency breaks modern setups #3

bwswedberg opened this issue Mar 18, 2024 · 0 comments

Comments

@bwswedberg
Copy link

bwswedberg commented Mar 18, 2024

Problem

This library is not functional out of the box when using a modern setup like vite v5 and typescript v5 which impacts @ngageoint/grid-js and @ngageoint/mgrs-js usage. It looks like the js_cols dependency is improperly bundled which blows up on "Uncaught ReferenceError: js_cols is not defined"

I'm unsure why exactly this works in commonjs vs es modules + vite. Regardless, js_cols does not have a very robust bundle (see https://github.com/thomasstjerne/js_cols/blob/master/dist/js_cols.min.js).

Ideal Solution

Shim or fix js_cols so that downstream users of libraries like @ngageoint/mgrs-js don't have to.

Steps to Reproduce

  1. Generate vite project i.e. npm create vite@latest my-app -- --template vanilla-ts
  2. Add the following to the index.html in the body tag
        <script type="module">
          import * as gridJs from '@ngageoint/grid-js';
          import * as mgrsJs from '@ngageoint/mgrs-js';
          console.log(mgrsJs.MGRS.from(gridJs.Point.degrees(0, 0)));
        </script>

Temp Workaround

See below for my temp temp solution. This defines the js_cols variable on global scope. It's later overridden when the library is imported.

        <script type="module">
          // This goes before the main bundle in the body
          window.js_cols = undefined;
        </script>

Environment

  • vite v5
  • node v20
  • typescript v5
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

1 participant