tools: [build] polymer build does not handle .mjs files
Unlike polymer serve, polymer build doesn’t know to treat .mjs files as JavaScript files.
import {
createStore,
compose,
applyMiddleware,
combineReducers
} from 'redux/es/redux.mjs';
~~~~~~~~~~~~~~~~~~~~
file:///Users/keanulee/Code/Polymer/pwa-starter-kit/src/store.js(16,8) error [could-not-load] - Unable to load import: No parser for for file type mjs
Another example: https://github.com/Polymer/pwa-starter-kit/pull/249
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 17 (13 by maintainers)
This would be more applicable to 3p libraries, for example https://unpkg.com/redux@4.0.1/es/redux.mjs (https://github.com/reduxjs/redux/pull/3143 from @TimvdLippe ).
Is there a way so Polymer prioritizes
.mjsfiles?I have a package with a bundle in a subfolder
And Polymer is picking up the
.jsfirst withimport { useEffect } from 'swiss-element/hooks';which results in an error because CJS modules are not supported.
This works however
import { useEffect } from 'swiss-element/hooks.mjs';I know it’s a small detail but my project uses suffix less syntax for npm packages…
Why not just use .js files?
See also https://github.com/Polymer/tools/issues/671
Patch: #792. Regardless of any one project’s decision to use
*.mjsor*.jsfor its source files, tooling must support*.mjssimply because people are using it.I think this immediate issue can be closed now that #792 is merged.
Is there any agreement around
.mjsextension set in stone anywhere so that we could refer to? The statement like “because people are using it” does not provide enough information about whether people are doing right and isn’t it too early to use that extension at this point.Especially, webpack maintainer expressed the position regarding
.mjshere: https://github.com/webpack/webpack/issues/7482#issuecomment-394838925IMO, #792 seems reasonable given the current “file extension implies media type” behavior of the analyzer. It might be nice to split this process into two steps at some point to help out with forward compatibility:
Rather than just
maybe doing something more like
and allowing the user to supply a ‘file to media type’ map + defaults for extensions somewhere like this
so that the process for taking a file and finding an appropriate parser becomes something like