Allow import of built-in browser modules, i.e. std:kv-storage
Created by: andria-dev
Should built-in browser modules be supported?
As it currently stands, CRA does not support built-in, standard library, browser modules and I haven't been able to find any information or discussion on future support for these modules (i.e. std:kv-storage
).
If built-in modules are to ever be supported it would make sense to use polyfills as fallbacks. CRA could handle polyfilling those modules itself or allow developers to provide a mapping of built-in module names to fallbacks (i.e. a URL or a module in node_modules/
).
Is this a bug report?
Yes
Environment
Browser: Chrome v74 (you'll need this to import std:kv-storage
)
Dev Environment: Codesandbox but the problem is everywhere
CRA version: 3.0.0
Steps to Reproduce
- Enable experimental web platform features on Chrome chrome://flags/#enable-experimental-web-platform-features
- Create a new project with CRA
- Attempt to import
storage
fromstd:kv-storage
inside any js file (I used/src/index.js
) like so:
import { storage } from 'std:kv-storage';
- Try to
console.log
the importedstorage
variable.
console.log(storage);
Expected Behavior
I expected the build to succeed by being able to identify that this import was referencing a built-in module because it was prefixed with std:
, and, therefore, not attempt to find and bundle a module called std:kv-storage
from /node_modules/
.
Since it didn't build the application, this part never happened but I expected the console.log(storage)
log the following to the console:
StorageArea {}
Actual Behavior
The build fails with the error:
Module not found: Can't resolve 'std:kv-storage'
Reproducible Demo
CRA unsuccessful build repro: https://codesandbox.io/s/4lw89q0l14?fontsize=14
Static example of importing std:kv-storage
:
https://codesandbox.io/s/7m87rjjk90?fontsize=14