-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[build] polymer build does not handle .mjs files #736
Comments
Why not just use .js files? See also #671 |
This would be more applicable to 3p libraries, for example https://unpkg.com/redux@4.0.1/es/redux.mjs (reduxjs/redux#3143 from @TimvdLippe ). |
I've opted for an awkward install step to fix the polymer builds in my project.
|
Patch: #792. Regardless of any one project’s decision to use |
IMO, #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 parsers = new Map<string, Parser<ParsedDocument>>([
['html', new HtmlParser()],
['js', new JavaScriptParser()],
['mjs', new JavaScriptParser()],
['css', new CssParser()],
['json', new JsonParser()],
]); maybe doing something more like defaultMediaType = new Map<string, string>([
['html', 'text/html'],
['css', 'text/css'],
['js', 'application/javascript'],
['mjs', 'application/javascript'],
['json', 'application/json'],
...userSuppliedDefaultMediaTypes
]);
parsers = new Map<string, Parser<ParsedDocument>>([
['text/html', new HtmlParser()],
['text/css', new CssParser()],
['application/javascript', new JavaScriptParser()],
['application/json', new JsonParser()],
]); and allowing the user to supply a 'file to media type' map + defaults for extensions somewhere like this {
// This section is used above as `userSuppliedDefaultMediaTypes`:
"extensionToDefaultMediaType": [
["es", "application/javascript"],
],
"fileToMediaType": [
["./path/to/a-file-with-a.strange-extension", "text/html"],
],
} so that the process for taking a file and finding an appropriate parser becomes something like function getParserForFileAtPath(path) {
if (fileToMediaType.has(path)) {
return parser.get(fileToMediaType.get(path));
}
if (defaultMediaType.has(extensionForPath(path))) {
return parser.get(defaultMediaType.has(extensionForPath(path));
}
throw new Error("Can't figure out how to load your thing.");
} |
Is there any agreement around Especially, webpack maintainer expressed the position regarding
|
@bicknellr That seems like a good follow-on change! It’s similar to the early Node.js plans of expanding their module support to non- @web-padawan I’m not sure what kind of data you’re asking for. Several people in this thread have pointed out issues with their builds failing because one of their dependencies uses The only “agreement” you need is that A one-line patch (#792) can fix this in polymer-tools. Let’s just make this work? |
If we split it up into the two phased 'extension → media type → parser' and make the 'extension → media type' step configurable, then we wouldn't need to take an opinion trying to predict Node.js' decision (i.e. merge #792) and could just let users that want
Weird, I was looking at this page which claims it was obsoleted: |
No need to predict, when there’s agreement on the “minimal kernel”, which states that:
The first point corresponds to #792. The second point corresponds to your proposal. I don’t think the former should be blocked on the latter. Re: the MIME type, indeed. IANA doesn’t really match reality. The IETF draft I linked to will codify fix this particular issue at the IANA level. (In practice, the MIME type doesn’t really matter as long as it’s a JS MIME type, but hey.) |
To clarify my earlier comment, I’ll respond to this:
Considering that users reporting this issue have stated that the Your proposal would be a great follow-up to enable more flexibility with other extensions, but |
Could you go into more detail about why that isn't sufficient? I think that the mapping is used for all files that the analyzer finds, not just those within your project. (#792 is based on this assumption, right?) |
I’m arguing that forcing your users to add a mapping for I share your assumption that both the default mappings (which #792 extends) + the custom mappings (which your follow-on proposal would enable the user to extend) would affect everything the analyzer finds. 👍🏻 |
I think this immediate issue can be closed now that #792 is merged. |
Is there a way so Polymer prioritizes I have a package with a bundle in a subfolder
And Polymer is picking up the which results in an error because CJS modules are not supported. This works however I know it's a small detail but my project uses suffix less syntax for npm packages... |
@luwes Did you find the solution for prioritize .mjs files? |
@hashamhabib no, I didn't find a real solution. Only explicitly defining the extension. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Unlike
polymer serve
,polymer build
doesn't know to treat .mjs files as JavaScript files.Another example: Polymer/pwa-starter-kit#249
The text was updated successfully, but these errors were encountered: