Clément Flodrops
Clément Flodrops

Reputation: 1104

Babel & Node : Error after transpiling ((0 , _express.express) is not a function)

I am writing ES6 in NodeJS env via Babel. So here is my .babelrc file :

{
  "presets": ["es2015", "stage-2"],
  "plugins": []
}

Yep, pretty simple. I'm using npm scripts to launch commands :

"build-server": "babel server/lib -d server/dist",
    "build-server:w": "babel server/lib -w -d server/dist",

And it works great. Under server/, I have a lib folder which contains my source code and a dist folder with 'babel-code'.

So typically, I can write this :

import { ModuleAPI } from './api/moduleAPI';
import { path } from 'path';
import { fs } from 'fs';
import { express } from 'express';
let app = express();

which is successfully transpiled to :

'use strict';

var _moduleAPI = require('./api/moduleAPI');

var _path = require('path');

var _fs = require('fs');

var _express = require('express');

var app = (0, _express.express)();

The issue is, when I execut node server/dist/server.js, an error is throwed :

var app = (0, _express.express)();
                               ^
TypeError: (0 , _express.express) is not a function

I've seen some 'similar' issues : https://stackoverflow.com/questions/35187535/using-babel-jest-and-get-typeerror-0-createclass3-default-is-not-a-functio webpack babel es7 async function error "TypeError: (0 , _typeof3.default) is not a function"

But I can't get my code works with Babel.

Any idea ?

Upvotes: 3

Views: 3823

Answers (1)

Ben Fortune
Ben Fortune

Reputation: 32127

You need to remove the braces around express.

import express from 'express';

express doesn't export an express property.

Upvotes: 10

Related Questions