Is the `.mjs` file extension resolved by metro bundler?
See original GitHub issueHi all, quick question as library maintainer, is the .mjs
file extension supported by metro? In order words, will a package json with a module
field like this work like with webpack (or is module
ignored completely, which would be fine as well):
"module": "lib/mobx.mjs"
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
All about Metro Bundler - Medium
A javascript bundler is a tool that takes in all your Javascript code, files and all the dependencies and puts them together in...
Read more >How to use Metro's config to not look for extension when ...
I'm trying to modify my metro. config. js file so that it will not ignore an npm package's main module. I can clearly...
Read more >How to Create JavaScript Libraries in 2018 (Part 2) - LiveChat
Sounds easy — it would be enough to create a file or a directory called “preact” in the root of our library and...
Read more >babel/plugin-transform-typescript
This plugin adds support for the types syntax used by the TypeScript programming language. ... It matches the tsc behavior when parsing .mts...
Read more >@apollo/client | Yarn - Package Manager
[Relevant if you use Apollo Client with React Native] Since Apollo Client v3.5.0, CommonJS bundles provided by @apollo/client use a .cjs file extension...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 thepackage.json
of all the libraries, pointing to an ES5/ES module file with old fashioned.js
extension. That works well with Metro.Hey @mweststrate! Thanks for bringing this up.
As you mention,
metro-bundler
does not take into account themodule
field onpackage.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 themain
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 makemetro
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.