admin 管理员组文章数量: 1086019
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.
本文标签:
版权声明:本文标题:javascript - Babel & Node : Error after transpiling ((0 , _express.express) is not a function) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744063236a2527112.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论