-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
SystemJS/CommonJS interop #8687
Comments
I think you are one of the first who experience the issue I described (in a different scenario): |
The only thing that works for me is modifying .d.ts files and replacing export=Promise by var Promise : |
Right now we need to get a better understanding of what the interop behavior will be. This is contingent on what the NodeJS Core Technical Committee (CTC) decides on. |
@DanielRosenwasser yeah, the addition of Edit: Hit enter prematurely. |
@DanielRosenwasser sorry I hit enter prematurely: what I meant to say was that I don't see how TypeScript can solve this problem without runtime semantics provided by node to accommodate easy consumption of default exports. If the semantics are introduced then TypeScript can model them. |
@DanielRosenwasser Should (CTC) decides on this or should it be ECMAScript spec group (or if they are closely related / one and the same. 😄)? We need to have a full spec of CommonJS -> ES2015 and ES2015 -> CommonJS interop. |
I don't necessarily know if the interop problem is one that TC39 itself needs to specify explicitly, though I think there are decisions that could be made there so that importing a CommonJS module from an ES module, and an ES module from another ES module, are more balanced experiences. Unfortunately, that doesn't seem to be the case according to the interop draft right now. |
Yeah, https://github.com/nodejs/node-eps/blob/master/002-es6-modules.md#5411-examples will still break #8840 |
From the wording of the proposal, or at least the disclaimer, it seems that the node community is still thinking about whether they will even adopt support for ES6 modules at all. That saddens me quite a bit. It fragments the community. |
It is not just node, right? Browsers also. So it really should be part of language spec. |
@unional well the browsers have committed to implementing the standard I suppose at some point. Certainly the module syntax, as it is part of ES2015. But since the browsers themselves don't currently have a competing implementation, projects like SystemJS polyfill it in a forwards compatible way, in the meantime providing de facto standard modules in the browser. The problem is that node has a competing implementation of modules. Considering how much time and energy TC39 spent trying to specify modules in a manner compatible with existing module formats, including CommonJS, it would be a real shame if node never adopted it. |
Ah, you are right. Browsers doesn't support commonjs natively..... Dumb me.... 😁 |
NodeJS have casted their vote: https://github.com/nodejs/CTC/pull/60/files#diff-2b572743d67d8a47685ae4bcb9bec651R217 Most important note:
import * as express from “express”
var app = express.default()
import express from “express”
var app = express() Breaking change to TS (and all existing TS code!) in order to align. UPDATE: |
This issue really should be a P1 and fixed asap. We have people start compiling TS to es6 and any reference to CommonJS will break. It is Babel/NodeJS/SystemJS vs TypeScript interop on CommonJS. |
I have creates a repro for this issue: https://github.com/unional/domture/tree/interop-issue In the repro, it demonstrates the difference between: // inside `@unional/logging`
export * from 'aurelia-logging'
import { getLogger as getLog } from 'aurelia-logging'
export { getLog } When you run the test, you will see that The situation will be the same if you import using import L = require('aurelia-logging')
console.log(L.getLogger) // [function]
import { getLogger } from 'aurelia-logging'
console.log(getLogger) // undefined |
cc @blakeembrey |
@unional I've been thinking about this quite a lot... I think there's a disconnect here that must be directly addressed. I think there has been a serious problem created by transpiling ES Module syntax to CommonJS semantics. What this comes down to, to some extent, is that many think that they're using ES Modules when they are not. There are many different factors in play here... but I think this problem is simply not going to go away and that it is absolutely critical that something is done to address it. I don't know what that should be exactly... |
Should be covered by #19675 |
Closing in favor of #16093 |
Hello, I have an issue involving SystemJS/CommonJS interop and definition files. I can't find any acceptable solution for now.
My app consists of
I cannot figure out how to import some libs like bluebird or lodash without having either the compiler complaining about something or an exception at execution level. I used definitions files provided by DefinitivelyTyped for bluebird/lodash.
I tried all import syntaxes I could find, but without success
import Promise from 'bluebird';
do not compile on CommonJS,import {Promise} from 'bluebird';
still do not compile on CommonJS,import * as Promise from 'bluebird';
compile on both CommonJS and SystemJS, but crashes during execution, on some functions that directly use Promise as constructorimport Promise = require ('bluebird')
old syntax compiles on both CommonJS and SystemJS. But crashes at execution on SystemJS, because Promise cannot be used directly as constructor/function.Do you have any solutions for this problem ? What is the right way to do in this case ?
The text was updated successfully, but these errors were encountered: