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

Support built-in modules #8896

philipwalton opened this issue Mar 11, 2019 · 4 comments

Support built-in modules #8896

philipwalton opened this issue Mar 11, 2019 · 4 comments


Copy link

philipwalton commented Mar 11, 2019

Feature request

What is the expected behavior?

Chrome is currently shipping KV storage (behind a flag, origin trial coming soon), which is the first of many planned built-in modules on the web.

The issue with webpack is that built-in modules are only consumable via native import statements, which webpack does not currently support.

Ideally, a developer would be able to include the following in their source code, and webpack (perhaps with the help of a plugin) would know how to optimally load it.

import {storage} from 'std:kv-storage';

storage.set('key', 'value');

What is the motivation or use case for adding/changing the behavior?

Built-in modules offer a way for developers to import code into their projects with no download, cost. And they're actually usable in production today because they have viable fallback mechanisms:

  • Import maps provide a fallback for browsers that don't support the built-in modules.
  • And module/nomodule builds provide a fallback for browsers that don't support imports.

The only thing preventing webpack users from using built-in modules in their projects today is that webpack itself doesn't support outputting in module format.

Note: if you're curious, here's a small demo (source code) of a site using built-in modules (via Rollup) and using the above fallbacks so it works in all browsers. In Chrome 74+ (with the experimental web platform features flag turned on), the built-in module is used. In all other browsers a polyfill is loaded.

How should this be implemented in your opinion?

In my opinion, the best way to enable this would be to add full support for ES module output, eliminating the current ES5 runtime code and depending entirely on import statements to load chunks.

But since I assume supporting ES module output would be a lot of work, it would be nice if (at minimum) webpack could be configured to preserve unresolved (or external) module import statements.

I've filed a separate issue for this feature. If support were added, I think it would make it possible (albeit in a slightly hackish way) for webpack users to use built-in modules in their bundles while we wait for proper ES module support.

Are you willing to work on this yourself?

I'm willing to help, but cannot commit to full implementation.

Copy link

glen-84 commented Mar 12, 2019

Possibly related: #2933, #8010.

Copy link
Contributor Author

@glen-84 definitely related, but I filed this separately because I suspect it may be easier to support built-in modules as an incremental change rather than needing to wait for full module support.

Copy link

@philipwalton PR welcome 👍

Copy link

vankop commented Apr 5, 2022

That trial has ended, and KV Storage is no longer available.

@vankop vankop closed this as completed Apr 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

4 participants