-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
import = require is silently swallowed with module: esnext #17556
Comments
Thanks for the report! This should just be a matter of issue of
We'd be willing to take a PR if you're interested! |
I wouldn't mind tackling this, if needed, but I would need some guidance, since this would be my first PR. |
Go for it! Some folks have recently been out and are catching up on bugs, but we'll try our best to give feedback. 🙂 |
Check out our Instructions for Contributing Code to TypeScript on our CONTRIBUTING.md. I think if you don't submit a CLA, a bot will prompt you when you send your PR. You can also look at some of my recent PRs (e.g. #17459) for inspiration. The workflow I use is
|
I started looking at this. This probably also needs a change for export assignment as well. I tried import foo = require("foo");
foo();
export = foo; With foo(); With
and the following code is emitted: foo(); I'll continue working on this and hopefully have a PR sometime this weekend unless you've make progress @captainSpades |
It looks like ES modules are eventually going to be supported natively in node.js. The intended purpose of import assignment is interoperability with node.js, so wouldn't it make sense to support that for The way things are headed now, there will be severe limitations on interoperability between ES modules and commonjs modules in node. If I write a library targeting node, for the time being I would likely need to distribute two sets of compiled files - one for commonjs consumers, another one to be used in new node applicatinons which are targeting ES modules. If my library has commonjs dependency, it's OK, but that dependency needs to be used with The problem is, I can't find a combination of options that will allow me to do that from single set of source files and type definitions. Transpiling |
TypeScript Version: 2.4.2 / nightly (2.5.0-dev.20170801)
Code
tsconfig.json
Expected behavior:
Not entirely sure what is expected to happen here:
"module": "commonjs"
emitsvar isUrl = require("is-url");
"module": "es2015"
errors withindex.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'im port * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
Actual behavior:
The compilation finishes without an error, but the import is missing in the output:
The text was updated successfully, but these errors were encountered: