Comments (7)
Hey @mweststrate! Thanks for bringing this up.
As you mention, metro-bundler
does not take into account the module
field on package.json
, so it should be safe to use this field in a library to expose .mjs
files as long as the package still exposes a .js
file in the main
field.
For now I think it's better to wait until .mjs
gets more traction (and Node ships a version with support for it) to implement proper support for modules in metro.
In the meantime, RN users can customize the sourceExts
config param (the same way you did for the default value in #60) to make metro
parse these files.
If there is a lot of demand of users wanting to use files with the mjs
extension, we could merge your PR, but for the time being I'd prefer to wait until the dust around ES6 modules settles.
from metro.
Tnx! Closed for now, after diving into webpack a bit further, it is not even supported officially there, so probably it is better to wait until webpack has figured it out :).
For now just added a react-native
field to the package.json
of all the libraries, pointing to an ES5/ES module file with old fashioned .js
extension. That works well with Metro.
from metro.
Had some collegues testing it, using .mjs
extension caused the bundler to fall back to the "main"
field containing the UMD bundle or our test package.
from metro.
Update: seems that module
or jsnext:main
are not picked up by the bundler in the first place. A react-native
field is picked up (deducted from source code, I couldn't find docs on that)
from metro.
What are future plans on this? I have to admit it is quite unobvious as library author how a library should be published to make it suitable for RN, without falling back to UMD / commonjs
from metro.
Closing for now, until .mjs has become a bit more mainstream. Still curious on thoughts around this though
from metro.
Please send a pull request to the resolution code in "ResolutionRequest", with tests, and we are happy to merge and support this functionality :)
from metro.
Related Issues (20)
- Duplicate files error while running was as react-native backend after reloading.
- React-Native ERROR Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., "myApp" has not been registered. iOS only
- Package Exports not working HOT 11
- `react-dom/server` cannot be resolved with `unstable_enablePackageExports` and condition `browser` HOT 5
- FATAL EXCEPTION
- SHA-1 for file C:\Users\Eportal\AppData\Roaming\npm\node_modules\react-native\node_modules\metro-runtime\src\polyfills\require.js is not computed. HOT 2
- unstable_enableSymlinks does not seems to work HOT 15
- Property "watcher.unstable_workerThreads" shows warning message when running Metro HOT 3
- unstable_enableSymlinks not work with library with react components with Babel transpilation
- Android font not shown even after linking
- None of these files exist HOT 2
- Cannot find module @callstack/out-of-tree-platforms after run `yarn start --reset-cache` in rn-tester app HOT 1
- How to use it in android tv?
- [Question]: Why is Metro hot update not affected by project size, as always fast HOT 1
- Issues with redux-saga when using unstable_enablePackageExports
- [website] "Fast", "Scalable", and "Integrated" images don't load.
- error: bundling failed: SyntaxError: Unexpected reserved type (any, string, func, Boolean ) HOT 1
- [Question]: Custom logo and welcome message on Metro server launch? HOT 4
- Metro on Windows: Cannot start server in new window because no terminal app was specified HOT 1
- Could not determine the dependecies of task ' :react-native-safe-area-context:generateDebugRFile' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metro.