skypackjs / skypack-cdn

An issue tracker for the CDN
107 stars 5 forks source link

Error with destructuring import being transformed into null default import #270

Open cryptographix opened 2 years ago

cryptographix commented 2 years ago

Hi, I'm having some trouble importing from skypack.dev, where a destructuring import is apparently being converted a default import which is null.

Steps to reproduce

test.html:

<!DOCTYPE html>
<html>
  <head>
    <script type="module">
      import FWE from 'https://cdn.skypack.dev/-/@microsoft/fast-web-utilities@v5.1.0-yXzMACgaLr8nuiCv5DHB/dist=es2019,mode=imports/optimized/@microsoft/fast-web-utilities.js';
      console.log( "OK" );
    </script>
  </head>
  <body></body>
</html>

Error: Uncaught TypeError: Cannot destructure property 'canUseDOM' of '__commonjs_module0' as it is null. at fast-web-utilities.js:2:8

Installing locally from npm, file node_modules/@microsoft/fast-web-utilities/dist/dom.js contains

import { canUseDOM } from "exenv-es6";

which is being converted to:

import __commonjs_module0 from "/-/exenv-es6@v1.0.0-fa4R8VP7dYtnxEIkhyvT/dist=es2019,mode=imports/optimized/exenv-es6.js";
const {canUseDOM} = __commonjs_module0;

whereas exenv-es6/dist/index.js contains

export * from "./can-use-dom";

and exenv-es6/dist/can-use-dom.js is:

export function canUseDOM() {...};
cryptographix commented 2 years ago

Maybe same problem as #269

bofeng commented 1 year ago

I am having the similar issue with a different package here:

<script type="module">
import { PeraWalletConnect } from "https://cdn.skypack.dev/@perawallet/connect"
</script>

Error:

Uncaught TypeError: Cannot destructure property 'isBrowser' of '__commonjs_module0' as it is null.

Screenshot 2023-10-13 at 8 45 10 PM