rollup/rollup-plugin-node-resolve

Add .mjs to default extensions

lukastaegert opened this issue · 7 comments

As this is becoming more and more of an issue, I think rollup-plugin-node-resolve should by default recognise both .js and .mjs files with a preference to the latter.

To my knowledge, this better reflects the default behaviour of node and will thus require less configuration from users.

Seems reasonable - webpack also has started to support this since v4. Worth pointing out that module should still take precedence over main, even if main has .mjs.

This is somewhat unfortunate as there are even more possibilities now for a file to be resolved differently when using bundlers & node and additionally there are gonna be 2 possible default extensions for both.

I guess you are opposed to adding .mjs as possible extension in rollup's core, which also lands things in some weirdo place where .js is allowed and .mjs is not 🤷‍♂️

mvila commented

I am not sure about the final specifications of ESM in Node (discussions are still ongoing), but it seems that the choice of the extension (.js or .mjs) is depending on the consumer (require or import). So, it's not only a matter of precedence; it might be slightly more complicated.

Found an issue with modules with mixed .mjs and .js files in a module as documented here #168 ...

tl;dr if package.json doesn't exist (ie when calling sub modules) it tries to resolve to index.js not index.mjs even though the module calling the sub-module is a .mjs file.

@antstanley Did you tried to replace extensions option?

sooo... found the problem. The updates to add .mjs support to rollup-plugin-node-resolve haven't been pushed to npm.

Closed my initial issue and added a new one as the problem was something else. New issue here #169

It also seems to me that those lines should use extensions