bundlejs icon indicating copy to clipboard operation
bundlejs copied to clipboard

Fail to bundle `npm/lib/cli-entry.js` and `@npmcli/arborist`

Open SukkaW opened this issue 1 year ago • 6 comments

https://bundlejs.com/?q=npm%2Flib%2Fcli-entry.js

The error during the bundling:

http-url:https://unpkg.com/[email protected]/lib/:1:1

Where https://unpkg.com/[email protected]/lib/ returns HTML (404) while https://unpkg.com/[email protected]/lib/index.js does return JS.

Is there any option that enables node-like resolving?

SukkaW avatar Aug 17 '23 05:08 SukkaW

https://bundlejs.com/?q=%40npmcli%2Farborist

This also faces the same error, also caused by the https://unpkg.com/[email protected]/lib/

SukkaW avatar Aug 22 '23 03:08 SukkaW

@okikio Would you like to add an option for node like resolving?

SukkaW avatar Aug 22 '23 03:08 SukkaW

I've determined the cause of this issue, but I'll have to delay fixing it by a little bit as I won't be available to fix it issue until a little later on during the week/weekend. This issue seems to be caused by the redirect unpkg.com does when you add a / to the end of the url. For example, https://unpkg.com/react will lead to react but https://unpkg.com/react/ leads to https://unpkg.com/browse/react/.

okikio avatar Aug 22 '23 03:08 okikio

I've determined the cause of this issue, but I'll have to delay fixing it by a little bit as I won't be available to fix it issue until a little later on during the week/weekend. This issue seems to be caused by the redirect unpkg.com does when you add a / to the end of the url. For example, https://unpkg.com/react will lead to react but https://unpkg.com/react/ leads to https://unpkg.com/browse/react/.

I've tried to switch to other CDNs, but all available CDNs have their flaws:

  • unpkg: doesn't support URL ending with / (redirect to browse view)
  • esm.sh: doesn't support externalizing Node.js built-in modules and doesn't support loading package.json
  • cdn.jsdelivr.net and esm.run: doesn't support node-like extension resolving (https://cdn.jsdelivr.net/npm/[email protected]/deprecated won't redirect to https://cdn.jsdelivr.net/npm/[email protected]/deprecated.json)
  • skypack: failed to load the entry

SukkaW avatar Aug 22 '23 04:08 SukkaW

I'm so sorry, I'll try my best to get this fixed when I get the chance

okikio avatar Aug 22 '23 05:08 okikio

I'm so sorry, I'll try my best to get this fixed when I get the chance

Don't worry. The issue is caused by the behavior of existing CDN providers, not by bundlejs.

IMHO, bundlejs could add a node-like resolver (maybe opt-in by an option?):

  • load the URL and parse
    • If failed to parse or 404 (this mimics fs.exists)
      • If the URL ends with /
        • Add a trailing index then load and parse that URL instead.
      • If the URL doesn't end with an extension (primarily seen in CommonJS modules)
        • Add extensions (.js, .cjs, .json), then load and parse each one of them.
        • Maybe use Promise.any here to parallel?

SukkaW avatar Aug 22 '23 05:08 SukkaW