Skip to content

Transpilation of ES6 imports is inconsistent with babel #5458

Closed
@eggers

Description

@eggers

Currently, babel and typescript handle transpilation of ES6 imports differently.

The following works in typescript:

import * as rp from 'request-promise';

rp('http://github.com').then(console.log);

but I get an error when running it with babel's transpilation:

TypeError: object is not a function
    at Object.<anonymous> (./test.js:7:1)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

To get it to work with babel, I have to do the following:

import rp from 'request-promise';

but that returns an error when compiling with typescript:

test.ts(1,8): error TS1192: Module ''request-promise'' has no default export.

I currently have a pipeline of typescript --tsc--> es6 --babel--> es5 so that I can use async/await while I wait for TypeScript to support it for ES5. However, that means I have to modify all my DefinitelyTyped declarations to have a default export so that tsc doesn't complain.

Discussions of which standard is better for transpilation put aside, my feeling is that TypeScript should follow the standard set by babel rather than using their own since babel is further along at supporting es6, and has a larger community at this point:

npm babel

33,936 downloads in the last day
174,998 downloads in the last week
551,455 downloads in the last month

npm typescript

15,303 downloads in the last day
101,148 downloads in the last week
357,086 downloads in the last month

In addition to keeping in step with the larger community, it would help adoption of typescript by making the transition to typescript from babel more seamless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions