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 mands :
"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 : 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 ?
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 mands :
"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./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 ?
Share Improve this question edited May 23, 2017 at 12:23 CommunityBot 11 silver badge asked Mar 23, 2016 at 9:50 Clément FlodropsClément Flodrops 1,1141 gold badge14 silver badges29 bronze badges1 Answer
Reset to default 10You need to remove the braces around express
.
import express from 'express';
express
doesn't export an express
property.