question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is the `.mjs` file extension resolved by metro bundler?

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mweststratecommented, Sep 19, 2017

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.

1reaction
rafecacommented, Sep 19, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found