TypeScript: Importing default module fails when using ES6 syntax
I have tried importing fs module using import fs from 'fs' but this gives an error: `Module ‘path’ has no default export.'.
import fs = require('fs'); works but this is not ES6 syntax. I would like to stick with ES6 syntax because it is getting more and more popular and therefore easier to understand.
Are there any plans for supporting ES6 modules that import the entire TypeScript module?
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 3
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Change export syntax, see https://github.com/Microsoft/TypeScript/issues/3337#issuecomment-109580444 — committed to ionic-team/legacy-ionic-cloud by imhoffd 8 years ago
You should use
You can use your syntax if the module has a default export. Example:
I suggest making the existing
export =syntax compatible withexport default. Right now it doesn’t seem possible to perform a default import of modules declared with the old syntax.Take the
tapemodule for example. I can’t import it using es6 syntax and the existing definition file. The following directive:Fails with
TS1192: External module ''tape'' has no default export.. If I change the definition file to useexport default tapeinstead ofexport = tapethen it works, but it will make the definition incompatible with typescript compilers < 1.5–allowSyntheticDefaultImports solved this for me, #2242 #5577
I used
And the error message becomes: