-
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
Unclear: How to import fromPairs from 'lodash/frompairs' #15426
Comments
TypeScript implementation for ES6 modules adheres to the spec, in the sense that It is important to note that the ES6 spec does not describe interop with CommonJS modules, as this is outside the scope of what the committee does. Also as per the ES6 spec, If you want to get the module object then use Obviously this does not work in the case of CommonJS modules that override the whole module object. our recommendation here is to use the pre-ES6 When TS implemented supported for ES6 modules, CommonJS interop story was not clear. i think we now have better understanding of what NodeJS will be doing moving forward and we should be able to allow importing CommonJS modules as |
To calrify my erlier commment, Today an import of the form: import d from "foo";
console.log(d); today emits to: var foo = require("foo");
console.log(foo.default); under the earlier proposal it would emit instead: var foo = require("foo"), foo_1 = foo && foo.__esModule ? foo : { default: foo };
console.log(foo_1.default); |
@mhegazy Thank you for the explanation - it's very helpful.
If I understand right, are you saying that you guys are planning to change emitted output for imported CommonJS modules to the above? If yes, is there an issue tracking it that I can follow? |
@DanielRosenwasser is working on one. we will be discussing it in the language design meeting this Friday. so stay tuned |
google closure also doesn't like these "fake" commonJS modules :p it never reads the |
I tried a few permutations and eventually the TypeScript-specific `import some = require('lodash.some')`, which works fine for the ES5 build, but not ES2015 per: microsoft/TypeScript#15426. Falling back to a standard `require` was the only way I could make this work (thus far). However, this means `index.es2015.js` is no longer an ES module. Lmk if there's a better way of this. Closes coatue-oss#36.
Any progress with interoperating with CommonJS modules? |
Any progress with importing CommonJS modules as es6 imports? |
#16093 tracks this work. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
I have been unable to find a clear explanation of what to do in this case:
Concretely:
I am trying to create 2 builds of my library: 1 that exposes a CommonJS export, 1 that exposes an ES2015 export. Concretely:
tsc -m commonjs -t es5
Succeedstsc -m es2015 -t es2015
Fails witherror TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules
Do I need to introduce System/Browserify into my build, or is it possible to get this to work correctly with TSC?
The handbook's advice is:
Relevant issues:
import * as module from 'module'
systemjs/systemjs#1251My full tsconfig.json:
The text was updated successfully, but these errors were encountered: