WRT PR #3 - ES module detection #13
Comments
jokeyrhyme
commented
Mar 10, 2016
|
Is it appropriate to discuss the ".jsm" extension proposal here? Or does it belong elsewhere? Or has that proposal been definitively rejected? |
|
@jokeyrhyme yes, you can discuss various approaches such as |
balupton
commented
Mar 10, 2016
|
I've tried to do a recap of the options for this at https://github.com/nodejs/node/wiki/ES6-Module-Detection-in-Node Personally, I'm proceeding with the userland solution of editions - with the current implementation of editions, there is @bmeck thanks for splitting this up |
|
@balupton lots of those are in the proposal / please avoid putting things that have not been agreed upon in the node wiki as it may confuse people. Feel free to paste all that in here and we will discuss it. I disagree with a lot of pro/con points and discussion should be had on them. |
balupton
commented
Mar 10, 2016
|
@bmeck point of the wiki page was to summarise all points, not just those agreed upon, so as to avoid having to read the entire previous thread for such depth, it should be expanded rather than truncated - discussion should happen here yes, however I see no wrongdoing with maintaining a comprehensive up to date concise summary of all points |
jmm
commented
Mar 10, 2016
|
I understand that there are a lot of objections to the idea of trying to inspect the source to detect the format, to the point that in the original thread people keep saying it's a dead issue, off the table. But yet it's still mentioned here, so as long as it's still in the mix I think the Something like a |
|
warning, in 2 weeks module proposal for node will be taking file extension unless package.json complexity and workflow concerns are addressed. If those concerns are addressed we will happily delay the decision. I will be confirming against the @nodejs/ctc that this is not a problem in this time as well. |
isiahmeadows
commented
Mar 10, 2016
|
Which one? Or is that still to be determined? On Thu, Mar 10, 2016, 14:14 Bradley Meck notifications@github.com wrote:
|
|
@isiahmeadows https://github.com/nodejs/node/wiki/ES6-Module-Detection-in-Node#option-4-meta-in-packagejson Notably:
As per the options, they differ for various ways to put things in |
|
It should be noted that the file extension has a sizable impact as well. It is not with a happy heart I choose between either. Also, the |
balupton
commented
Mar 10, 2016
|
@bmeck "Is there any plans to support files that use both module systems (aka CJS+ES Modules)?" is specifically about a file that supports both, rather than a package that supports both, here is a contrived example: import a from 'a'
const b = require('b')
export b
module.exports = aAnother phrasing would be, does each file have to be exclusive es modules, or exclusively node modules, and never mix and match in a single file. This arose once or twice in the other thread, but I couldn't find anything clear about it, hence why it is there, doesn't seem raised in the proposal explicitly - perhaps is implied somewhere and I didn't notice. Currently with the babel compiling, mixing and matching module systems in individual files is already being done. great work with the wiki updates! |
|
@balupton that is not supported, @kittens tried that rabbit hole in babel, it is pure zalgo. If you are in the Module goal there is an |
balupton
commented
Mar 10, 2016
Just raised myself because I know of babel compiled projects that do such mix and matching. I've found myself having such quarrels too, specially with optionally required dependencies (a dep may only need to be required under special circumstances, e.g. for a specific function call which in the majority of runs will never be called), or with dynamic dependencies (e.g. |
calebmer
commented
Mar 10, 2016
|
I subjectively fear losing the I think @jmm’s suggestion of A parsing solution does not impact in place systems. In place systems can happily assume CommonJS. An extension approach, however, widely impacts multiple software ecosystems. Whereas a parsing solution only effects new code. |
balupton
commented
Mar 10, 2016
|
How about |
|
@balupton as discussed in the original PR thread, that is not how many toolchains work, they only read the final extension (this includes @calebmer can you discuss the technical implications. There are many problems with parsing, and polyfills are a very common instance of side-effect only modules. |
ljharb
commented
Mar 10, 2016
|
@calebmer in-place systems being unable to use ES6 modules is a massive impact. |
calebmer
commented
Mar 10, 2016
|
@bmeck ok, and I'll address the side-effect only concern and the other CONs listed in the wiki. But first I'd like to offer three observations: First, we have to remember that no solution can be ideal. The ideal scenario would be that the ES module specification was around at node's conception so that modules could be supported from the start. That didn't happen, so we now have the tricky task of picking a way to add module support to node whilst not breaking the ecosystem. The parsing solution mirrors most closely what node would look like if there was module support from the start. Second, theoretically the parsing could be as simple as a regular expression matching Third, the extension, Now to counter arguments. Side-effect only modules.Most of the time a side-effect only module could easily be a script (optionally with a The intersection of side-effect only files and files which must be a module is very tiny, and the tax of a single line is insignificant and comparable to Toolchains require a parser.Many tools which need to know the difference between a script and a module already have a parser, furthermore many more tools don't even need to tell the difference. For the select few tools which need to know the difference and can't use a small parsing solution from NPM, these tools can use out of band configuration. Take for instance the Furthermore, tools that can't have a simple parser for NPM often aren't in the node ecosystem (I'm thinking of Ruby, Python, or other ecosystem tools). These tools are dealing with client code, not node code. Large files.Considering Babel and other parsers currently can work with large files I'm not entirely sure why this is a large concern. If we use a regular expression parser and a parallel file extension like I recommend these pains can also be alleviated. Solutions may also include:
Performance.In a normal project, all dependencies will be imported/required at startup time which is less critical for performance. However, in some scenarios this is not the case. In areas where dynamic requiring must be performant we can look into various algorithm coercing approaches. For current packages we can also look at the |
calebmer
commented
Mar 10, 2016
|
@ljharb sorry for any miscommunication. I meant in-place systems won't be negatively impacted by a parsing solution, a parsing solution would be neutral. I was referring to the |
ljharb
commented
Mar 10, 2016
|
@calebmer one common use case where a parser won't work is Airbnb's rails app - which uses Sprockets, which sends JS files to an entirely different box for compilation. It will have to know what is an ES6 module or not so it can send the right metadata to the compilation service - but it has no JS engine to do so. Also, perhaps you haven't tried reading JSON in POSIX, but "not needing a parser" is pretty critical in some places :-) |
calebmer
commented
Mar 10, 2016
|
@ljharb A couple questions as I don't entirely understand the Airbnb-rails-sprockets-node relationship. Why can't Sprockets choose to implement its own format (maybe extension)? Why can't the compilation service make the detection? If the detection of modules were as simple as a regular expression would this alleviate concerns? It seems to me that services, like Sprockets, have a little more freedom then node to make large breaking changes. If Sprockets wanted to assume everything was a module or everything was a script it could. |
ljharb
commented
Mar 10, 2016
|
@calebmer the problem is that it doesn't want to assume that - we need to be able to gradually migrate our codebase from script to module. We also don't want Sprockets to implement something that wouldn't work with |
jokeyrhyme
commented
Mar 10, 2016
|
Do we need to know which mode we are in prior to parsing? |
jmm
commented
Mar 10, 2016
|
I don't have time to respond to everything here right now, but regular expressions are not adequate for detecting this, though like you said a regex or substring search could be useful as a quicker preliminary check to see if
I think it's possible that placement in the source could be used to optimize this detection, as I mentioned in my original post:
But making it dependent on that would probably be too fragile, though I did try something like that with browserify for recognizing its own bundles. (That's a much more limited scenario though since it's designed to check its own output.) |
jmm
commented
Mar 10, 2016
What would be an example of that? (Probably makes no difference to the issue at hand, I'm just curious what you mean.) @jokeyrhyme Yes, because they're different goal symbols and modules are implicitly strict. People might have expanded more in the original thread. |
ljharb
commented
Mar 10, 2016
|
@jmm just responding to the question "Why can't Sprockets choose to implement its own format" - the answer being, because one-off snowflakes are not ideal for being cohesive with the rest of the ecosystem/toolchain. |
balupton
commented
Mar 11, 2016
Isn't that exactly why Consider the impact of
Consider the impact of
The only toolchain that needs to be aware of the file using ES Modules in this use case in this scope, is node... Using It seems forgotten that outside of node people already use ES Modules successfully with the Happy to be linked to the places this has already been discussed in case I have missed something. But it seems it solves all of @calebmer's objections to the
Given the sprockets argument... they can just adopt the Again, the beauty of |
calebmer
commented
Mar 11, 2016
|
@ljharb why can't babel be used until a reasonable amount of the codebase has been converted? Also a comment like I'm not convinced that there is a big enough need in tooling to know the difference between a script/module and further I'm not sure the "one-off" snowflake detection is a bad thing considering most build tools already have a snowflake configuration format.
That's actually a really cool point, but it still has negative precedent setting impacts. What happens when developers start writing |
balupton
commented
Mar 11, 2016
Good points. Possible ways they could be addressed.
Point 1.i is nice as it can do a "business as normal" approach to custom extensions like |
jokeyrhyme
commented
Mar 11, 2016
|
My own experience with the Regarding sprockets, if there is demand for Regarding Assuming multiple proposals for mode-flagging are not incompatible, why don't we just do everything and see which ones the community embraces? Surely we could enhance Node.js to do the following:
If it's hard to get consensus around a single approach, is it possible to implement the top 2 or top 3? |
caridy
commented
Mar 11, 2016
|
guys, please, stop thinking about the pragma detection. we have exhausted that conversation via different channels, the number one goal of ES Modules is portability, and not all environments has the ability to analyze the code before it is parsed and evaluated like node can, and implements will NOT support a parser that mixes modules and sloppy mode scripts. please, stop it, and focus on realistic solutions. |
|
Generally file extensions are contained to 3 letters ( https://en.wikipedia.org/wiki/8.3_filename ) and do not include a @ljharb you might have opinions on this? |
jmm
commented
Mar 11, 2016
That's what I thought from the original thread, but it's not remotely clear that this issue which was opened 2 days ago is saying that. This issue appears to invite that discussion by specifically referencing determining the mode given a source string and alluding to the same drawbacks to that concept that you're referencing, that were brought up in the original thread. If that's just your personal opinion, ok then. Otherwise please clarify the messaging. |
|
@jmm it is dead. no parsing. it was dead in the original PR comments as well. The edge cases mentioned and added burden for toolchains is too much. |
jmm
commented
Mar 11, 2016
|
@bmeck Please clarify that in the OP here. This appears to invite that discussion. |
caridy
commented
Mar 11, 2016
Narrowing down the use caseThe whole discussion here is due to the fact that we might have components that are mixing CJS and ES Modules, and our estimate (from few of us) is that this is actually a very minor use-case. To help with that, lets try to describe when you need to mix. The NO casesWhen we talk about mixing CJS and ES modules, we are explicitly talking about code in the context or node runtime, and that does NOT include: i. files used by a runner can have an out of band configuration when invoking node We might have other cases that fits into this bucket, but I think you get the idea. You, as the author the pkg, have full control over how the file is used, and when it is used, it is easy to solve that with an out of band configuration, and we should not care much about that for now. The cases1. Gradual transition to ES ModulesIn the middle of a refactor, developers might end up in a situation where they have part of the module using ES Module format, but still using CJS for some pieces of the package. In this case, there is another important question: will those modules be in the same folder structure? note: I haven't seem evidence of mixing files in the same folder when transpiling with Babel and co. 2. Missing capabilities in ES ModulesES Modules are suppose to be a superset of CJS, but at the early stage we might have missing capabilities, things that can only be achieve when using CJS, this will force early adopters to keep some CJS modules in order to achieve certain tasks that otherwise will be impossible by using ES Module format only. @the problemThe problem we are trying to solve here is how to signal the format of those files that should be parsed and evaluated by node runtime, while trying to avoid a huge tax on authors. And as today, we have two buckets on the table: i. detection by path (a decorator on the filename, a decorator on a folder name or a custom extension) Next steps
|
Like 1/2 of times I run |
Most likely since this is green code, the real problem is large existing code combined with the "Missing capabilities in ES Modules". In particular with extenrally mutable exports, circular dependencies, and top level await. |
calebmer
commented
Mar 11, 2016
The argument for a parsing solution is that it is the best out of many bad solutions. Edge-cases for a parser can be solved, performance hits can be optimized, and there are adequate alternatives for the tooling which needs it. Compare this to the far reaching negative technological and cultural impacts of I want to reiterate that the parsing solution mirrors most closely what modules would look like in node if implemented from the beginning. This is important for developer experience and for our eventual migration to an ES module only ecosystem with the lack of any vestigal structures. |
|
@calebmer the 2 parsers have ambiguities if done on the same source text, that is the edge case. It cannot be solved. Tribal knowledge to unroll ambiguity is not acceptable. End of discussion on parsing from a technical perspective. As @ljharb mentions parsing is prohibitive to toolchains. End of discussion for ecosystem. Do not continue discussion on parsing, if you wish to please comment on the original PR but it cannot produce ambiguity and it must be non-prohibitive to toolchains at the very minimum. |
caridy
commented
Mar 11, 2016
elaborate
all aside from that, I recommend you to look into all TC39 notes related to |
zenparsing
commented
Mar 11, 2016
What is a decorator here? |
jokeyrhyme
commented
Mar 11, 2016
I believe this refers to something like I apologise for my part in continuing the pragma discussion. As for file path decorators and out-of-band settings (package.json, node CLI flag, etc): We could wait until Node 8 to deprecate the less popular one, and Node 10 to drop it, if we had evidence that a winner had finally emerged. RE: out-of-band: this does seem to be what the browser folks will be offering, with |
caridy
commented
Mar 11, 2016
|
@zenparsing decorators:
@jokeyrhyme asking for both is fair enough, in fact, we have discussed that in the pass briefly. I asked for a mechanism that allow pkg author to hook into the loading mechanism to specify what parser to use per file. This mechanism does not exists today, the only mechanism that exists today is a loader extension which affects the entire process, we will need artifact, per pkg and/or folder, that can be used by node, and whenever a file inside that folder structure needs to be inspected, a function call of some sort will have to be executed, passing the path, as a result, it return the type. something along those lines, which means people will likely create abstractions for the cases where they mix CJS and ES. It might worth exploring it. |
|
@jokeyrhyme all solutions will require the cli flag, which is why there is a note in the issue head about it not being terribly relevant; it is only there to patch a specific case, it does not work as an interop at scale. |
zenparsing
commented
Mar 12, 2016
|
@caridy Gotcha. It feels like both solution candidates have unresolvable issues:
Seems like a stalemate. Maybe it's time to take another look at the |
ljharb
commented
Mar 12, 2016
|
@zenparsing not so much a stalemate if concerns about the |
zenparsing
commented
Mar 12, 2016
|
@ljharb Understood, but forcing the issue would prolly be not so good. : ) Anyway, at the risk of being annoying here's an example of a "fat package" when using the |
balupton
commented
Mar 12, 2016
|
Regarding my earlier proposal: I've added a note in it to verbosely explain that 1.i would still support
I fail to see how this argument is suitable. My point was that the
Not correct, my earlier suggestion means |
zenparsing
commented
Mar 12, 2016
Who wants to type in |
balupton
commented
Mar 12, 2016
Then just use However, if the developer's environment, tooling, server, whatever doesn't yet support It would be the one I want to do, as it would work with all my existing tooling without any changes to them. |
zenparsing
commented
Mar 12, 2016
|
If you support both
I'll make the stronger claim that only a minuscule amount developers will want to use such a long extension. |
balupton
commented
Mar 12, 2016
Do you mean "If you support both
Aesthetics choices are only possible if they are available. If their situation doesn't allow |
ljharb
commented
Mar 12, 2016
|
@balupton using |
|
|
isiahmeadows
commented
Mar 17, 2016
|
@domenic I was thinking the same, but I was a little hesitant to mention anything with multiple extensions because there seemed to be some practical objections with that in the first place. (Not that tools couldn't be fixed, but that's another deal.) |
balupton
commented
Mar 18, 2016
These sound like much easier solvable problems than the alternatives. |
|
@balupton @isiahmeadows @domenic my fear is that this means any tool that only parses the last |
isiahmeadows
commented
Mar 22, 2016
|
@bmeck I get that. To be perfectly honest, I'm more of a bystander in this discussion, anyways. As long as I'm not having to add a (By the way, I do like ES6 modules. Don't get me wrong. |
This was referenced Mar 24, 2016
|
@bmeck |
benmosher
commented
Apr 4, 2016
|
I'd like to offer a "why not both?" solution (see jokeyrhyme's last comment). Analogously to the existing This means that a package author may define a glob, if needed or desired, but may also use modules without defining a custom glob by following the default glob, which is essentially some chosen file extension. Having read through this thread, I hope I didn't miss any major technical shortcomings or disqualifications. Here goes, as JS pseudocode, for clarity and specificity: const path = require('path')
// assuming these exist, are performant, cached as appropriate, etc.
import { findPackageForPath, loadPackage } from 'core'
import { satisfiesGlob } from 'glob-utils'
// not critical what these are ultimately defined to be
import { MODULE_GLOB_KEY, DEFAULT_MODULE_EXT } from 'bikeshed'
const DEFAULT_GLOB = `**/*.${DEFAULT_MODULE_EXT}`
/**
* Determine if a file at a given path is an ES module, and should
* be parsed as such, without inspecting the file's contents.
* @param {string} absolutePath - full resolved path to file (i.e. /my/app/path/cool-module/index.js)
* @return {Boolean} - true iff file at path should be parsed + treated as module
*/
export function isPathModule(absolutePath) {
let packagePath = findPackageForPath(absolutePath)
, packageObject
if (packagePath != null) {
packageObject = loadPackage(packagePath)
} else {
// implicit package at folder (a la index.js)
packagePath = path.dirname(absolutePath)
}
let glob
if (packageObject != null && MODULE_GLOB_KEY in packageObject) {
// use package-defined glob, when available
glob = packageObject[MODULE_GLOB_KEY]
} else {
// use default
glob = DEFAULT_GLOB
}
return satisfiesGlob(absolutePath, glob, {
relativeTo: packagePath,
})
}In cases where infrastructure cannot parse JSON, application authors simply need to respect the chosen default convention. In cases where a new file extension would cause immediate burden, a custom glob may be defined. I think this covers the concerns raised in this thread without being too complicated or potentially expensive at runtime, assuming the package locations/objects and glob definitions can be cached per-directory during process startup and module load. Again, apologies if I missed anything while reading through the thread that would disqualify any or all of this. |
|
In case it didn't propagate to here, at nodejs/node#5866 most of the CTC preferred a module extension (discussed was |
|
@Fishrock123 I don't think that we settled on the specific extension, though. |
|
correct, tc39 met last week and I was holding any discussion until I get the meeting notes. |
|
Correct, we didn't settle on an extension, but we did discuss the |
|
Those are also present in npm packages.
On the other hand, |
|
@ChALkeR looks like most of the .jsm are coming from $ grep source-map < jsm.txt | xargs basename | sort | uniq
SourceMap.jsm
Utils.jsm
prefix-source-map.jsm
prefix-utils.jsm
suffix-source-map.jsm
suffix-utils.jsm
$ grep -v source-map < jsm.txt | wc -l
83So looks like |
|
@isiahmeadows Wow. Thanks, I missed that! |
jokeyrhyme
commented
Apr 5, 2016
|
Alternatively, |
ljharb
commented
Apr 5, 2016
|
|
isiahmeadows
commented
Apr 5, 2016
|
@ChALkeR Welcome |
rubennorte
commented
Apr 12, 2016
|
I think we should go for the |
|
Due to the prolific use of RegExp and Glob lean slightly towards I do have concerns as well if Updating EPS to be |
jmm
commented
Apr 15, 2016
|
For globbing |
caridy
commented
Apr 15, 2016
|
wow, we are getting down the rabbit hole with the extension proposal. btw, our timeline to share the counter proposal should be ready early next week. |
|
@caridy rabbit hole? |
|
In the event of a counter proposal, we will still need to verify any assumptions / impact it may have even outside of node itself. Such scrutiny will be applied to any direction taken. Support for other tooling / environmental implications / developer experience / potential exploitation are not to be considered a rabbit hole. |
|
I don't really see why something locally in a web browser should effect us, where will that confirm-ably overlap? |
isiahmeadows
commented
Apr 15, 2016
|
Once On Fri, Apr 15, 2016, 13:58 Jeremiah Senkpiel notifications@github.com
|
|
@Fishrock123 what @isiahmeadows said and also the fact that some test runners do in-browser testing generally over the |
zenparsing
commented
Apr 19, 2016
|
+1 to renaming the language MichaelJacksonScript. |
isiahmeadows
commented
Apr 20, 2016
|
@bmeck I'm not sure how relevant |
|
@isiahmeadows please see the note in the EP ( https://github.com/bmeck/node-eps/blob/es6-module/002-es6-modules.md#reason-for-decision ), Firefox loads |
Jeff-Lewis
commented
Apr 21, 2016
|
So for applications & packages written in ES+Babel now with .js extension, what is their expected upgrade path (dev & CI environments) to use native ES6 modules in node? Also, for applications & packages using CJS modules in node 4+ with ES classes and where majority of the code is already using existing ES features in node 4+, what does their upgrade path look like? |
jokeyrhyme
commented
Apr 21, 2016
•
CJS modules that work in Node 4 and use
|
isiahmeadows
commented
Apr 21, 2016
Only if an explicit
That is allowed.
It'll happen, though. ES6 modules are far superior, IMHO.
You can still use |
jokeyrhyme
commented
Apr 21, 2016
•
|
@isiahmeadows @Jeff-Lewis Oops? I was under the assumption that the module resolution folks were voting in favour of making Node.js strictly match browser behaviour, with no resolution magic Probably best following up those comments in the other thread, as it might be beyond the scope of "module detection" to discuss that any further here. |
isiahmeadows
commented
Apr 21, 2016
|
@jokeyrhyme I'll take that back, but only partially. That's still being discussed, and one of the biggest concerns about requiring explicit extensions and paths is that people are already depending on Node's algorithm with Babel when targeting either platform. |
|
@bmeck heya, you should submit a talk about all this for Interactive :) https://www.conferenceabstracts.com/cfp2/login.asp?EventKey=VSIHQOEU |
This was referenced Apr 23, 2016
jokeyrhyme
commented
Apr 27, 2016
rektide
commented
Apr 27, 2016
•
|
This thread seems entirely devoted to how Node wants to carve a special case people need to opt in to to use ES6 Modules. Using an extension other than .js is hideous and not JavaScripty, and Node should bend over backwards to make itself maximally JavaScripty and not a special case demanding X Y or Z. As a developer in 2018, I will be writing JavaScript with JavaScript modules and those modules- used by front and and back end- WILL be .js files. If Node wants to make it hard to run actual JavaScript on Node, it should proceed with the current idea of requiring a special extension (.jsm): Node can go off and do that and then anyone who wants to use normal, regular code will have to "transpile" (rename the file) my actual JavaScript to Node JavaScript. But I suggest you avoid this obvious terrible horrific looking jank of carving out your own extension. My suggested heuristic, in loose form:
This favors a happy path, and falls back to the current set of assumption. Node should try to just do right. There are very simple heuristics to determine when the attempt to use actual modules (es6m) has failed, and then fallback and retry. Using an extension other than .js seems like it will break, look jank, and be hideous, in the dual-sided world we're in. I haven't seen any solid arguments as to why explicit coaching is required from node. We should milk a source detect solution as best as we can, and only fallback to explicit coaching of node. And if node is going to be so crippled as to need explicit help, it should at least kindly read it out of the meta-data payload node already relies on, package.json, rather than stomp the normal signalling people use to indicate they're writing js. as a developer, i would way rather write that looks good and normal than mutilate normal looking filenames for node's sake. i'd rather write packages broken for node that look normative and let consumers babel transpile my .js to your funky weird .jsm than distribute bizarre files. if node wants to not be JavaScript, it invites in the need to build chain JavaScript to run and consume npm packages. I've mined the thread for what I can find about source-detect, and this is what I've rounded up:
|
isiahmeadows
commented
Jun 2, 2016
|
@jokeyrhyme Problem is, many CommonJS modules require that their source is parsed as sloppy, or they just don't use the pragma. |
jokeyrhyme
commented
Jun 2, 2016
My "what can we ship now?" suggestion/question side steps that by forcing module/strict parsing on anything that is So options that people are using now that would continue to work would be to use |
ljharb
commented
Jun 2, 2016
|
@jokeyrhyme anything partial we ship now will actually end up making it harder to ship something else later, because packages will be published that rely on the "shipped now" behavior. |
jokeyrhyme
commented
Jun 2, 2016
|
@ljharb Go 1.5 shipped with an experimental vendoring solution (now stable in 1.6): https://medium.com/@freeformz/go-1-5-s-vendor-experiment-fd3e830f52c3 Also, we previously had a Any chance we could get something basic and experimental in, hidden behind a flag? Or have a hook enabled via a flag, so that the different proposals can be poly-filled or something? |
ljharb
commented
Jun 2, 2016
|
Both proposals can be polyfilled right now, in every version of node, via monkeypatching require.extensions. It wouldn't be performant, but it would simulate the ergonomics. I don't think anyone has built a polyfill yet for either approach. |
rubennorte
commented
Jun 2, 2016
•
That proposal already covers that. Also, if it weren't covered you could keep using |
jokeyrhyme
commented
Jun 2, 2016
|
@ljharb but |
martinheidegger
commented
Jun 2, 2016
|
Perhaps this could help: I took the time and tried to summarize the information I could comprehend here: https://github.com/martinheidegger/es6modules-nodejs I would love it to brush this up and ask the broader Node.js community for input/help. |
ljharb
commented
Jun 2, 2016
|
@jokeyrhyme you'd need to use something like babel on-the-fly when requiring files that were modules, since import/export syntax isn't supported - which is how |
shelby3
commented
Jun 2, 2016
•
|
It occurred to me that with a file extension proposal, it is plausible that the module field for However, all other factors weighed, I prefer not to make a proposal dependent on eliding the file extension in order to achieve single-point-of-truth, because the file extension eliding can be an orthogonal concern. Another fundamental design principle I adhere to is trying to maximize degrees-of-freedom when there is no overpowering negative cost to doing so. However that still doesn't ameliorate the other disadvantages of a file extention proposal. Also I added other disadvantages upthread, including the requirement for the module to maintained with two separate file extensions since not all use cases will employ the That is why from my current knowledge of the issue, it appears to be a "no brainer" decision. And that is why I became rather vocal and flabberghast about there even being any argument. In general, files should identify their format via content and not context, so that the attributes are carried with the file ven in the context is not, i.e. a single-point-of-truth. I understand that parsing Of course I don't relish being perceived as boorish, overbearing, condescending, or rude. I admit I was put off by the comment that alleged I had no valid argument (which I astutely perceived was sort of groupthink political attack against me because I was criticizing the logic of @bmeck), which then caused me to feel more competitive and I crushed the logic of the person who wrote that. Bottom line is I think crowd sourced design can be good at collecting all the community information around an issue. And crowd source design can catch errors in thought processes that one person or a smaller groupthink might miss. But the downside of crowdsourcing, is that an astute person who attempts to cut directly to the clear conclusion, may be perceived as against the groupthink theme of crowd sourced wisdom. Not. There are tradeoffs. I just want to see us not slide into lack of focus and most relevant priorities. This sometimes becomes difficult to do without a leader. And not that I want to be that leader on this issue. I was just sucked into this by a relevant need I have. Apologies to be so verbose, but just this one time so my demeanor is clearly explained. I don't intend to cultivate a political reputation, because I think politics detracts from efficiency and correctness of outcomes. Ultimately an alpha-male benevolent dictator rises and success results, e.g. Linus Torvalds. It isn't going to be myself on Node.js. Not my priority work set. If @bmeck wants to be the that dude, he needs to step up his astuteness to a higher level. When you see males do this sort of thing, it is because we want leaders who are as good at what they do as Linus. And I think we all know how abrasive he can be when he thinks someone has poor logic and reasoning skills. I am more patient than he is, until I see that groupthink political crap starting, then I go off the rails. |
|
@shelby3 I have worked quite hard to not interact with you in this issue, primarily because you do not come off as acting in good faith. I am going to take a few snippets from your last comment to highlight why people may feel this way
Now interestingly enough you state that you If you want to contribute to this project and have a vested interested in the future of the platform I suggest you take some time to examine the way you have behaved in this thread and come up with ways to improve. Trying to explain your demeanor in no way makes it appropriate. |
othiym23
referenced
this issue
in npm/npm
Jun 2, 2016
Closed
Better support for multiple module formats #4323
isiahmeadows
commented
Jun 2, 2016
|
Second question: what about languages that compile to ES2015 modules? In particular, this will immediately include Babelified, TypeScript, and some CoffeeScript projects (some do ES6 imports in backticks), but it will also include any other compile-to-JS language that at least plans to support ES2015 modules. This is more orthogonal of a concern, but it can indirectly affect both design and implementation of this feature. |
ljharb
commented
Jun 3, 2016
|
@isiahmeadows either approach (extension or manifest) will work just fine with any transpiler/compiler process imo, just like both would work with a polyfill - one might be slightly more complex to handle than the other, but it's pretty negligible, and I don't think it impacts the approaches either way. |
tsteuwer
commented
Jun 26, 2016
|
My concern for using a new extension ( |
ljharb
commented
Jun 26, 2016
|
@tsteuwer you'll already need that, because in one browser modules will be supported, and in another, they won't - whether you're keeping |
shelby3
commented
Jul 31, 2016
•
|
@thealphanerd how can expressing my analysis of the facts be "not acting in good faith" in any case. Your reply to me is just playing politics in a crapbucket mentality, so I can only wish you the utmost enjoyment of your political mess. Obviously you didn't like my attempt to say that I am going to speak the facts even if they offend others, and that it is not my preference to offend but when it comes to a choice of BS or truth, I'll choose the latter when it is important to do so. Any time you want to actually debate the facts instead of "worked quite hard to not interact with you in this issue", you might be useful to the process of excellence. |
|
@shelby3: such comments are better left to private email or Twitter and do not serve to move the conversation forward here. |
RobertWHurst
commented
Dec 16, 2016
•
|
New a extension seems like a poor choice for the future of the platform. This is the kind of decision is huge, and defines the future of the platform. I suggest careful thought here (clearly there's been a lot already |
ljharb
commented
Dec 16, 2016
|
@RobertWHurst extensions have no relationship to the browser, as browsers have always ignored them - and the "whole point" of ES modules wasn't "to sync with the browser environment", since browsers had no concept of modules prior to this. Any mechanism (of which "extension" is one) that helps serverside tooling distinguish Modules from Scripts actually makes it easier to share code with the browser, long term. |
RobertWHurst
commented
Dec 16, 2016
•
|
@ljharb Ok, thanks for straightening me out on that. To clarify, I meant the effort here of implementing to ES6 modules within node, not ES6 modules in general. I was a bit unclear there, sorry about that. Ah ok. I didn't realize the extension was ignored in the browser environment. So if one were to require a module with an import statement in the bowser, would the browser be able to resolve that module if it has the new extension? import foo from './my-npm-module' // trying to import my-npm-module.jsm
I'm not sure what you mean by this. How might this help share code with the browser? Don't we want to see the use of modules rather than scripts across the board eventually? Hopefully my question makes sense. Thanks for your time |
ljharb
commented
Dec 16, 2016
|
@RobertWHurst there needs to be a way for the server to know when to set a |
RobertWHurst
commented
Dec 16, 2016
•
|
@ljharb I gotcha, that makes sense. But if we use the extension to determine the module system don't we loose the ability to load our modules directly in the bowser via import statements? Perhaps I miss understand. Heres an example of what I mean. Lets suppose async is updated to use the jsm extension. A developer exposes async's source then tries to load it in the browser as follows. Wouldn't this break? import parallel from './async' // trying to import async.jsm |
ljharb
commented
Dec 16, 2016
|
@RobertWHurst in the browser, you have to import from URLs - so either you'd have to use a server rewrite rule to transparently turn an |
RobertWHurst
commented
Dec 16, 2016
•
|
@ljharb Right, ok. I see. Thanks for explaining that This is exactly what I'm afraid of. I do really think this is a problem for isomorphic js. I suppose people could be encouraged to add the extension, but as you say, I'd imagine they likely won't. Perhaps my alarm here is unique, but isn't this a bit troubling? One could argue that build tools would be involved. They are required today for shared code. I guess I was just holding out for the day we could retire some of the complexity around front end tooling in this regard. As an aside, I suppose it's to late to get the browser vendors to adopt the new extension for modules as well. |
cebor
commented
Jan 13, 2017
|
V8 should support ES6 modules now. |
|
@cebor it fully supports the parser and runtime, it does not declare any interop strategy or detection of when to use the Script vs Module parser when you get a source text (that is up to Chromium if you look at that issue). |
chyzwar
commented
Jan 26, 2017
|
But It should possible to ship modules without into node? Can we have some kind of wiki for this issue? |
|
@chyzwar not really, you couldn't do anything like |
chyzwar
commented
Jan 27, 2017
•
|
I could by creating adaptor modules like. Adaptor modules can be created in user-space and be temporary fix before interop arrive. fs.js export default require('fs')In most cases I do not need node.js native modules. In typical express.js application most of this is already abstracted. It is very rare that you need to call something outside path/fs modules. Issue I am facing now is that you need to use webpack/babel/node-esml to write ES6 code where you loose errors stacks/sensible debbuging ... Thanks for wiki :) |
isiahmeadows
commented
Jan 28, 2017
|
If I recall correctly, the current leading idea is to just resolve all
CommonJS modules as default exports. It avoids most of the interop mess, so
the only issue deals with underspecified timings.
…
|
isiahmeadows
commented
Feb 3, 2017
|
If we do go with // child_process.mjs
import child_process from "./child_process.js"; // force local resolution somehow
export default child_process;
export const ChildProcess = child_process.ChildProcess;
export const fork = child_process.fork;
export const exec = child_process.exec;
export const execFile = child_process.execFile;
export const spawn = child_process.spawn;
export const spawnSync = child_process.spawnSync;
export const execFileSync = child_process.execFileSync;
export const execSync = child_process.execSync; |
jokeyrhyme
commented
Feb 3, 2017
|
@isiahmeadows when you say "preferred", do you mean by an algorithm? Or by the silly fleshy creatures that type in the |
isiahmeadows
commented
Feb 3, 2017
|
I mean by algorithm.
…
|
Jamesernator
commented
Feb 15, 2017
|
Personally I like the Has there been any developer polling on which prefix would be preferred, and have multiple extensions been considered? |
|
See older versions of the EP
https://github.com/nodejs/node-eps/blob/39d52cab16886a749dc229331e916a1369bf3b0e/002-es6-modules.md#511-reason-for-decision
, it was removed as extraneous information.
…
|
chyzwar
commented
Feb 22, 2017
•
|
@bmeck Would be possible to change proposal for gradual adoption of ES Modules.
There is no need for new extension. Also in my opinion that perfect situation to improve main in npm to support root directory, It would be nice if we can "mylib/function" instead "mylib/lib/function". This would a separate issue. |
ljharb
commented
Feb 22, 2017
|
@chyzwar considering that there are npm modules that will never be updated, but are still in heavy usage, what makes you think that a staged approach will change the interop requirements? There should never be a time when node supports ESM but you can not seamlessly import CJS or require ESM. |
chyzwar
commented
Feb 22, 2017
•
|
I am not saying that introp requirements would change. At stage 3 node would provide full interop. I am just suggesting that node can introduce es6 modules now. There is no need for year of discussions and another year or implementation work . Interop is enhancement and not essential feature of ES6 modules. To be honest CLJ should be retired at some point in future node20?, aim should be on unification of JS world where node.js is central piece. There plenty of use cases where ES6 modules make sense even without interop: CLI applications, webpack config files, isomorphic applications, new projects etc. JS world is used to churn, adoption of ES6 modules could be faster than most people think. |
jokeyrhyme
commented
Feb 22, 2017
•
|
@chyzwar it was stated earlier that it would be undesirable for a consumer to have to know whether the package they are consuming was written in module or script mode. Ideally, they should be able to Of all the different facets (performance, compatibility, developer experience, availability etc) that need to be taken into consideration, I'm personally torn over which we can afford to prioritise and which we can postpone / ignore. |
chyzwar
commented
Feb 22, 2017
•
|
@jokeyrhyme your customers are developers and are not brainless. Everytime you consume library you will at least read readme installation and sample usage. And even if you make a guess you will still get descriptive error message. You can even add even more descriptive messages in debug mode.... You can still use require inside ES6 Module, since require return "something" and have no side effects in current module. I do not see that as issue. It is trivial to provide fat module with entry point This issue is open for almost a YEAR with no significant progress. I was waiting for many months before commenting in this thread again hoping that there is going to be some work done. |
ljharb
commented
Feb 22, 2017
|
Shipping nothing is better than shipping a partial feature when it has the potential to massively pollute the ecosystem. |
|
@chyzwar Implementation has already started nodejs/node#11233 , contributors will be getting access to a prototype in next few weeks (which will most likely be buggy) and after cleanup a prototype build will probably show up. To note, the v8 C++ implementation of modules is not entirely stable/complete and |
bmeck
referenced
this issue
in nodejs/node
Feb 28, 2017
Open
tracking issue: async loader for module interop #11233
|
As per nodejs/node#11233 (comment) , a protocol was briefly mentioned at one point as |
chrisveness
commented
Feb 28, 2017
|
I just came across a nodesource blog ES Modules and Node.js: Hard Choices by Rod Vagg (translation of an article by Yosuke Furukawa) – not sure how I missed it before – which seems to me the best summary I've seen. If I understand that article well, the interoperability decisions mean that I like the perspective that In Defense of .js prioritizes a switch from CommonJS to ES Modules for the longer-term future, and the Node.js EP prioritizes compatibility and interoperability. |
ljharb
commented
Feb 28, 2017
|
@chrisveness which is why the best practice continues to be (and has always been) to do |
jpolo
commented
Mar 4, 2017
|
What about jsx extension ? This conversation seems very long and raises so many potential problems. |
ljharb
commented
Mar 5, 2017
|
The jsx extension is why it's a best practice to omit extensions. If I rename a |
protoEvangelion
commented
Mar 7, 2017
|
Really looking forward to native |
cref
commented
Mar 11, 2017
•
|
I'm sorry if I'm missing something here but why complicate matters by trying to make CommonJS module example
ES6 module example
Yes, as a developer, you will need to know whether you must It's also trivial to write a wrapper module for either format so you could wrap all the cjs modules you need inside es6 modules and just use There will be a transitional period in which the use of Modules that belong to the Node.js API could be made available in both formats in some way or another so CommonJS Node.js API example
CommonJS Node.js API example
Calling an es6 script as the main script would require adding a flag for es6 mode or wrapping the es6 module. Possibly, the default behavior could be to autodetect the module format.
Compared to other proposals, this proposal doesn't introduce any added runtime overhead. (if you don't count the optional suggestions for using wrapper modules and main script format autodetection) |
ljharb
commented
Mar 12, 2017
|
@cref because it must be (possible to make it) invisible to consumers whether you're using CJS or ESM, which means you need to be able to refactor from one to the other (in either direction) without forcing consumers to update their code. |
cref
commented
Mar 12, 2017
•
|
Which can easily be realized by wrapping modules. Either offered by the library author or by creating or generating them yourself. Also, updating a library to a new major version will always force you to update your code, it's what versioning is for. |
jokeyrhyme
commented
Mar 12, 2017
|
@cref I think what we're trying to avoid is another Python 2 -> 3 situation, where compatibility is broken just enough to require work on everyone's part, the community is split for years, sharing of code is harder, etc. Eliminating / minimising the impact on the community is extremely important |
ljharb
commented
Mar 12, 2017
|
Right - changing the module format should be a patch or a minor, not a major - that's the point. |
cref
commented
Mar 13, 2017
•
|
Maintaining compatibility is the responsibility of the library authors, just as it is with regular changes to a library's API. What I'm trying to say is that it's peanuts to keep offering both flavors of a library to make both cjs and es6 developers happy. Say you have a library at version 3.x. You can then start a 4.x es6 version while still supporting 3.x without much effort. (either 3.x wraps 4.x or the other way around) |
jokeyrhyme
commented
Mar 13, 2017
|
@cref I'm sure everyone here completely sympathises with your viewpoint, as we all desperately want One other thing to note is that Node.js is not the only place where work must be done to support https://bugs.chromium.org/p/v8/issues/detail?id=1569 Node.js cannot support modules until a stable release of V8 includes the required foundations for it |
Mouvedia
commented
Mar 13, 2017
|
@jokeyrhyme that's not entirely true we could rely on https://github.com/nodejs/node-chakracore Oh the irony :) |
|
Last I checked, chakra was not 100% bug free as well.
…
|
ljharb
commented
Mar 13, 2017
|
@cref i think you're underestimating how important it is for it to be easy to support both. Citing Python 2/3 is appropriate here - if ES modules are not painless to migrate to, both for authors and consumers, people simply won't migrate en masse, and the ecosystem will suffer. |
chyzwar
commented
Mar 13, 2017
•
|
@ljharb @jokeyrhyme people are bringing Python case that is not relevant in this case. Python changed semantics of fundamental things in language: like how strings work, build-in functions print, integer division etc..Node is trying to introduce new module system according to existing spec. There no change in language or user-space code. It is pity that you cannot downvote everyone that mention python 2->3. In fact by trying forcefully bring interop between CLJ and ES Modules, node will introduce break in language. It is ironic that node is trying prevent a case of Python fragmentation by introducing break that will inevitably bring fragmentation. Explicit is better that implicit, when consuming a dependency developer should know format to use: require of import. By making this hidden will introduce a compatibility layer with subtle bugs and an extension that nobody outside node.js will use for theirs JavaScript. Since extension will be not present in import, I will never know when reading code what exactly is loaded.... Also by providing this compatibility layer there will be absolutely no incentive to migrate to ES6. |
isiahmeadows
commented
Mar 13, 2017
Which of these options do you think is the most breaking for users?
Here's what would happen:
I can tell you separating the two has already caused some fragmentation in the community. Consider
Webpack 2 tells a different story here. It natively transpiles both ES modules and CommonJS modules, with full interop. Additionally, it mostly targets browsers.
Yet again, Webpack has allowed some seriously flexible dependency chains, including with CSS modules (using Oh, and for other similar reasons, it's considered best practice to omit the extension. In particular, non-JS languages using other extensions (notably JSX, TypeScript, etc.) will try to load the wrong extension if you don't.
False. By most accounts, and in my experience, ES modules are way easier to work with for initial startup once you have the toolchain set up, especially in terms of exporting and scaling. You also get better static analysis with // CommonJS
const fsp = require("fs-promise")
const express = require("express")
const {map, flatten, matches: match} = require("lodash")
module.exports = function foo() {}
exports.bar = bar
function bar() {}
class Baz {
// ...
}
// Exported for testing
exports.Baz = Baz
// ES6
import * as fsp from "fs-promise"
import express from "express"
import {map, flatten, matches as match} from "lodash"
export default function foo() {}
export function bar() {}
// Exported for testing
export class Baz {
// ...
} |
chyzwar
commented
Mar 13, 2017
•
ES Module spec do not include CLJ import semantics. By adding interop you change ES Module spec and you have no control over how this will play in future. Maybe in ES 2020 module system in JS will change/extend and whole thing will blow?. Are you 100% sure that interop layer that you want to introduce do not have corner cases or bugs or security issues? Can you leverage perf optimisations available to ES Modules when running in interop mode? My biggest issue is still new extension, not only it create fragmentation from day 1 but it would force every possible tool and beginners tutorial to add this details.
That not true and we know that. If there is no incentive people will never migrate to ES Module. You still have modules written is ES5 even when from node4 you could use a lot new language futures. Heck people are still using
lodash-es exist only because ES Modules are not widely supported. One day lodash will decide that ES modules are supported in node/browser and it only publish ES Module version. But thanks two node we will still have
You have react.js version 15 and node 7, I do not see people screaming. Node can introduce two major version a year and libraries cannot do one ? I do not need dynamic import, I can temporary create adaptor to ES Module in CLJ module and use
Transpilation !== Interop. Webpack bundle JS for browser and in most cases module system is only used for compile optimisation not module loading itself. There no CLJ in browsers an the transpiration is only temporary because node do not support ES6.
I know that ES Modules are better technical solution that why I am pushing so hard to get this right. Not everyone is this passionate to argue with random people in the internet about module system :p People like you and others in this thread will be early adopters, most node.js user do not care. In my option node.js as platform should make right things easy and wrong things difficult. It should be easy to use ES Modules and CLJ should be discouraged. |
Just use
See above.
Unclear on this. I think the suggestion is when bumping you drop support for older versions which don't natively use ESM. This is not necessarily true. People do feature detection for things at runtime when available, by providing a safe upgrade path we can continue this pattern when using modules.
Agree, it transforms to a different system.
Disagree. People use
Correct, Webpack et. al translate things into a CJS implementation and ship that into browsers even though browsers do not provide CJS implementations natively.
I think all the people in these talks are very invested in this. It has been talked about for more than a year just on how to implement them. The idea of JS modules (called packages in ES4) has been talked about since the early 2000s.
I agree, but don't see how |
Mouvedia
commented
Mar 13, 2017
For the ones wondering: ES4 Packages |
chrisveness
commented
Mar 15, 2017
|
If we followed the In Defense of .js proposal, we wouldn't need file extensions in require statements. Alternatively, what is happening with the ES spec changes that Allen Wirfs-Brock suggested may be considered by TC39? Would that not also remove the requirement for an alternative file extension? I fail to see what is wrong with semver-major for CJS -> ESM. Any consumer of a library neeeds to reference the documentation for the library, and will see an announcement that a new semver-major needs to be imported rather than required. Changing module syntax can still happen incrementally in large code-bases. The wider JavaScript community will use .js for ES-modules (because ESM is after all standard JavaScript); if Node uses .mjs, then .mjs files will be seen as ‘Node.js’ modules, separate from normal ‘JavaScript’ modules. And we will have a permanent schism in the JavaScript community. |
ljharb
commented
Mar 15, 2017
|
The wider JS community uses node-driven build tools, as does the entire npm ecosystem. What node does, everyone else will follow. |
chyzwar
commented
Mar 15, 2017
•
Internet run on PHP and jQuery. I can guarantee to you that nobody will reconfigure tools like: code editors, CI, asset pipelines, build systems. All that web-servers, http cache, firewalls, proxies, corporate intranet, CDNs and who knows what else will stay away from .mjs.
Front-end people have absolutely no reason to use .mjs. For them there is no benefit. .mjs is only useful if you decide to write back-end in node.
With .mjs and full interop there will be no business justification to upgrade a code base. I work in large corporate environment and you will never persuade your business to spend few days just because of syntax. If there is major release of many libraries you will have argument for migration. My other concerns about interop are still there:
|
novemberborn
commented
Mar 16, 2017
This would prevent libraries from moving to ESM until the Node.js versions they're targeting all support it. Distributing ESM will require dropping support for current LTS and maintenance mode versions, or forking your distribution, e.g. |
cref
commented
Mar 16, 2017
•
|
Here's an idea: You need cjs and only cjs? use Node 9- You want some potentially buggy, performance degrading interop layer? |
mgol
commented
Mar 16, 2017
|
@cref That's a perfect way to make no one in the world using Node 10 and, in the end, someone forking Node.js again with support for CommonJS back in. This would be way worse than the Python 3 situation. |
cref
commented
Mar 16, 2017
|
That's fine by me if they can accomplish a workable solution. |
mgol
commented
Mar 16, 2017
|
You can hardly call a "workable solution" something that would make the number of Node users dwindle away to something close to 0. |
cref
commented
Mar 16, 2017
•
|
What's in a name. We'll just call io.js node.js again once the number of node.js users has reached zero if that makes you feel better. |
jkrems
commented
Mar 16, 2017
|
I don't think the io.js reference is relevant to this discussion. It's not like io.js made any big breaking changes. Most node 0.10 code worked fine on io.js (and still does on node master). What you're suggesting is stopping support for every single existing node program & library. This was never even considered for io.js (afaict at least). It would just create yet-another-unrelated-runtime that happens to reuse some code from node. |
mgol
commented
Mar 16, 2017
|
@cref You misunderstood. If Node ever dropped support for the whole current npm package ecosystem, someone would fork it to a version that kept CommonJS support. People would never upgrade to a Node version that dropped CommonJS, they'd migrate to the fork that keeps the support. The newest Node version would get abandoned and - maybe - in the future the fork would be renamed back to Node.js. So we'd end up exactly where we are now, the only difference would be a lot of problems with yet another fork in the meantime. What's the point? |
cref
commented
Mar 16, 2017
•
|
exactly, the name is not relevant, thanks for the confirmation. now where did I suggest stopping support? starting a new version !== ending support. ask microsoft. and why would you fork node for something you could just as easily solve with a library? is it because... you can't, because actually, anyway, I'm done, got some forking to do! :-P |
isiahmeadows
commented
Mar 17, 2017
Public Service AnnouncementTL;DR: Please remain respectful, and don't blindly reject others' viewpoints without taking the time to explain why they're wrong, not why you're right. I feel this discussion has somehow degenerated to the point it's borderline off-topic and not exactly productive, to put it lightly. Not pointing fingers, but could we at least listen to those collaborators here, most of whom having been involved with Node.js for most of its history? Oh, and if you feel someone's logic is off, please actually try to debunk it rather than just restating your point. Doing the former is proving them wrong, and it's usually something that you can do without even stating your side at all. Doing the latter will convince no one who doesn't already agree with you, and it'll make you look much less nice or respectful. To summarize, please remain respectful, don't be dismissive, and do consider the other side. You might be surprised what you would learn with an open mind! |
chrisveness
commented
Mar 17, 2017
|
@isiahmeadows I agree entirely; but I would like to point out (hopefully respectfully) that I think there is a sense that when it comes to |
cref
commented
Mar 17, 2017
|
Good point @isiahmeadows . All I'm doing here is offer some outside-of-the-box alternatives. IMHO, what's the most important aspect about es6 modules is the fact that it's a format optimized for both filesystem-based and web-based usage. Adding support to Node.js by introducing yet another file extension that's implicitly being searched for when fetching a module undermines the modular aspect for web-based platforms and would force web developers to still use additional build tools. Let's just wait until the Loader spec is finalized and then see how best to support loading Node.js-flavoured CommonJS through |
ljharb
commented
Mar 17, 2017
|
Web developers already have to use additional build tools to get anything useful done - that's the new reality. |
chyzwar
commented
Mar 18, 2017
•
Please do not conflate back-end and front-end development. There is number of language that do not require any additional tooling: go, Java, PHP, Python etc. Currently in node.js we barely have any editor support: auto completion, debugging, profiling. Node is now planing to introduce forced marriage between ES6 Modules and CLJ and make whole thing even worse. Can someone designing interop can confirm following: import {join} from 'path'This will load only join or whole path module? import {sharedApi} from 'https://cdn.syndication.twimg.com/api.js'
const sharedApi = require('https://cdn.syndication.twimg.com/api.js');
const {something} = require('esModule')
const something = require('esModule').something
import myModule from './myModule.js'
export default const something = {}
exports.default = {}
|
|
@chyzwar please read #39 for answers regarding most of these.
Won't work. Only
Open issue : #51 , current judgement is that you do not, but some people on browser side are concerned about that. Note, web browser support Searching so called "bare" URLs (things in
Not planned. Added complexity and does not focus on a future where there is a uniform way to produce code for ESM. This affects both browser vendors and node; both are well aware of the situation.
This is not possible according to the JS specification due to:
Modules only have 1 type either CJS or ESM. Therefore there is no priority since there is no competition. I would note that interoperability does not mean 100% compatible in both directions for our goals. Node is not going to limit its features to web browser APIs, and web browsers will not allow the same features as Node. |
|
The implementation of ESM has started, I am going to close this. If you have specific concerns about pathing or a problem with the file extension, please open a new issue. General concerns have been covered here in depth. |
bmeck
closed this
Mar 18, 2017
isiahmeadows
commented
Mar 19, 2017
•
I am also aware of that, but they have already previously addressed nearly every viewpoint presented here in the last week viewpoints earlier in this issue, #3, #39, and other related issues. It would've been definitely more helpful and productive if more of them had linked to previous discussion to justify their dismissal, but I do agree with their unwillingness to accept these arguments which have been covered multiple times already. (I've been passively involved and watching this closely since about a month after #3 was filed early last year, and I haven't seen much actually new come up in the last few months.) But on that note, this issue is closed, so I'm going to drop the issue now. |
gabrieledarrigo
commented
Apr 29, 2017
|
Hi! Where can fe follow the development of ESM? |
shelby3
commented
May 19, 2017
•
|
Lol, Node.js forking itself away from the ECMAScript ecosystem with a proprietary file extension total order on the universe and conflated interroropt of module specifications. Purrrfect. |
ljharb
commented
May 19, 2017
|
@shelby3 that comment isn't productive or accurate. Browsers ignore file extensions entirely; ECMAScript is a spec, not an ecosystem; people use Again, the reality is this: a file extension is supposed to mean only one thing: "here's how to parse this file". The creation of a second parsing goal in the language - Module - inevitably ensured the creation of a new file extension to indicate "parse this file as a Module". Feel free to suggest a better alternative, but the only possibility for avoiding a second file extension vanished when the language spec shipped a second parsing goal. That may be unpleasant for people - but that doesn't change the reality. |
SEAPUNK
commented
May 19, 2017
•
|
Just curious: Does the browser require the returned MIME type (via |
chrisveness
commented
May 20, 2017
|
I like that Node.js has become "everywhere but in browsers". |
ljharb
commented
May 20, 2017
|
@chrisveness do you know of non-node non-browser tools that take no out-of-band instructions (including "the only paths it accepts are JS files") and know something is a JS file by something besides the |
shelby3
commented
May 20, 2017
•
|
@ljharb wrote:
Pride cometh before thy falleth. Other things (e.g. TypeScript) are gaining momentum and eventually they might decide it is a lower priority to keep pace with more Node.js aberrations, especially after this epic fiasco causes more people fork away from Node.js.
TypeScript determines what is a module by whether it contains any top-level
As @chyzwar, @cref (and to some extent @chrisveness) have explained (which I consider carrying forward the original points I made in this thread last year), trying to backport Also unnecessarily providing two ways to do the same thing (i.e. You all the gatekeepers who are in control of the intended echo chamber, groupthink here, want to make it very easy for old code to be switched over to ESM by changing the module file names instead of changing all the @skaller commented on Oct 10, 2016:
Regarding exceeding the complexity budget, please see the comment quoted (not my comment but rather some very smart programmers who visit 160 IQ genius Eric Raymond’s blog) near the end of this post about how horrendous JavaScript’s chaos has become. Edit: I had mentioned this complexity overload in my first post last year, and even pleaded to be respectful of the users like myself. The complexity is so bad that no one without days to kill can even wrap their mind around all the epic volumes of arcane discussion that a reader is slammed with. K.I.S.S. is important. Transitioning towards one module standard that works every where is the sane direction that reduces complexity over time. edit: edited by @MylesBorins. replaced unfortunate choice of words with "echo chamber". I believe that keeps original intent in tact |
ljharb
commented
May 20, 2017
•
|
@shelby3 please don't use inappropriate terms like "circle-jerk" - https://github.com/nodejs/TSC/blob/master/CODE_OF_CONDUCT.md may be helpful.
(I'll be happy to delete this comment after/if you edit your post) |
shelby3
commented
May 20, 2017
•
|
@ljharb, the COC says you should not accuse my joke of being not productive (passive aggressive political control methodology) which you (and your cohort gatekeeper) also did to me last year, when it was a concise way of pointing out my technical objections without getting into another fight with you gatekeepers. Since you responded that way, I responded in kind. I tried to keep it light and humorous, but you want to fight because you are sure you are correct and everyone who disagrees with you is wrong. Edit: last year I even I tried to convince the politik to leave the ad hominem aside, but was unsuccessful. Sent in a private msg just now:
|
gabrieledarrigo
commented
May 20, 2017
|
Ok but, anyone knows the status of the work on ES modules? |
|
@shelby3 it sounds like you have some interesting arguments to make and discussion was conductive until 2-3 messages ago. I realize that strong opinions sometimes lead to strong language or terminology but Node really cares about being a nice environment and it would be a shame if we missed your insights into the problem (to be clear, completely serious here) because of the way discussion is had. I realize it's a little unfair to ask you to have discussion in the particular way we're asking and that you're entirely within your right to refuse - but I would much rather prefer you stick around :) |

bmeck commentedMar 9, 2016
This is the place to discuss specifics of how node will determine the mode a given a source (file / source string). Source string examples include stdin or
-e, they do not include JSFunctionorevalcalls. The proposal itself can be seen in PR #3.Discussions here should regard:
Note: CJS will be the default target of
nodefor the foreseeable future, "normal" here means what developers write daily. This is a constraint that can be easily worked around for a single source via a cli flag to note that the source is an ES module. This flag should not be seen as relevant to the discussion in this thread.Note: We are only discussing choices that do not require parsing of the source file.
It should not discuss import/export conversion, evaluation ordering, or module path resolution.