Search code examples
javascriptecmascript-6babeljstranspiler

error when importing modules with es2015 syntax and babel transpilation to es5


I got problems with transpiling es2015 code to to ES5. Problem happens with module imports:

import * as express from "express"

is transpiled to:

var _express = require("express");
var express = _interopRequireWildcard(_express);

Which cause the error:

var app = express();
          ^
TypeError: express is not a function

But if I import with

var express = require('express');

all works fine.

I still want to use es2015 syntax, is there a setting or plugin I should Install in bable to have it work properly ?


Solution

  • Use

    import express from "express"