mjs files get imported as static files
See original GitHub issueHello,
Here is a repro :
import graphql, { parse, buildASTSchema, buildClientSchema } from 'graphql'
console.log(graphql, parse, buildASTSchema, buildClientSchema)
// ouput : /static/media/index.497f5ee2.mjs undefined undefined undefined
Excluding the .mjs
extension from the file-loader
fix the issue.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Import JavaScript modules on client side : .js or mjs
The following question (What is the difference between .js and .mjs files?) is really interresting, but is focused on server-side (node.js).
Read more >How to import JSON files in ES modules (Node.js) - Stefan Judis
Learn about the ways to read and import JSON files in Node.js ECMAscript modules (ESM).
Read more >CommonJS vs. ES Modules: Modules and Imports in NodeJS
You are not able to import .mjs files from .js files. This is due to the different nature of the two systems. Dynamic...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax.
Read more >Getting Started with (and Surviving) Node.js ESM
my-app/file.mjs // Static: top of file, only string imports import colors from "colors"; // _Only_ `default` export (`{ green }`) import ...
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
@jaydenseric
👋 Node core and Node Module WG member here. Just a heads up, there is no set date for when
--experimental-modules
will be unflagged. There’s also no guarantee that what has shipped now is what will be in the future. The Node Module WG does not recommend using--experimental-modules
for production use.Bundling mushes transpiled code, CJS, ESM, and
.mjs
code together. Things can get a little funky.👍
@Timer
Yep. It’ll do 😎
@Timer
It’s still pretty hard to get things right with the current state of things. For example, even
graphql
has issues working with--experimental-modules
with mixed CJS and ESM use. It’d be helpful to avoid any solution that makes.mjs
viral (requiring consumers, or deps of deps to be renamed to.mjs
to get things bundled properly).Projects like Babel 7, webpack 4, and
esm
restrict.mjs
use or implement more-strict rules when handling experimental.mjs
files. However, Babel and webpack can be configured to handle.mjs
in less-strict ways. I think complications may come from webpack enforcing itsjavascript/esm
for.mjs
by default, instead ofjavascript/auto
for the moduletype
.