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

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

Open
SukkaW opened this issue Aug 17, 2023 · 6 comments
Open

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

SukkaW opened this issue Aug 17, 2023 · 6 comments

Comments

@SukkaW
Copy link

SukkaW commented Aug 17, 2023

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

The error during the bundling:

http-url:https://unpkg.com/validate-npm-package-name@5.0.0/lib/:1:1

Where https://unpkg.com/validate-npm-package-name@5.0.0/lib/ returns HTML (404) while https://unpkg.com/validate-npm-package-name@5.0.0/lib/index.js does return JS.

Is there any option that enables node-like resolving?

@SukkaW
Copy link
Author

SukkaW commented Aug 22, 2023

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

This also faces the same error, also caused by the https://unpkg.com/validate-npm-package-name@5.0.0/lib/

@SukkaW SukkaW changed the title Fail to bundle npm/lib/cli-entry.js Fail to bundle npm/lib/cli-entry.js and @npmcli/arborist Aug 22, 2023
@SukkaW
Copy link
Author

SukkaW commented Aug 22, 2023

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

@okikio
Copy link
Owner

okikio commented Aug 22, 2023

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/.

@SukkaW
Copy link
Author

SukkaW commented Aug 22, 2023

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/spdx-license-ids@3.0.13/deprecated won't redirect to https://cdn.jsdelivr.net/npm/spdx-license-ids@3.0.13/deprecated.json)
  • skypack: failed to load the entry

@okikio
Copy link
Owner

okikio commented Aug 22, 2023

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

@SukkaW
Copy link
Author

SukkaW commented Aug 22, 2023

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?

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

2 participants