0
我正在使用resity
和babel
編寫應用程序。在我route.js
:Babel導出默認功能錯誤
export default respond = (req, res, next) => {
res.send('hello');
next();
}
我index.js
:
import restify from 'restify';
import route from './route';
const server = restify.createServer();
server.get('/bonjour', route);
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
和我.babelrc
:
{
"presets": ["es2015", "stage-2"]
}
編譯後,其輸出route.js
:
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = respond = function respond(req, res, next) {
res.send('hello');
next();
};
當我運行node index.js
,我有以下錯誤:
exports.default = respond = function respond(req, res, next) {
^
ReferenceError: respond is not defined
誰能解釋爲什麼會發生。謝謝。
感謝你的詳細答案。我正在開發一個react-native項目,並使用上面所做的相同語法。它的工作原理讓我認爲模塊捆綁器在這種情況下不僅僅是Babel本身。 –