最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 10

You need to remove the braces around express.

import express from 'express';

express doesn't export an express property.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论