我想在服務器上使用node.js與webpack和babel-loader(es2015 +階段0預設)使用javascript ES7語法。我已經得到了它與巴別塔節點的工作,但是當我運行的WebPack我得到async關鍵字以下錯誤(9:22是async關鍵字後):錯誤使用ES7異步/等待與節點,webpack和babel-loader
ERROR in ./src/server.js Module parse failed: C:\dev\node-async-sample\src\server.js
Unexpected token (9:22) You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (9:22)
我已經把代碼放在github在https://github.com/qubitron/node-async-sample,關於如何讓這個工作的任何想法?
這裏是SRC/server.js的相關片段:
import express from 'express';
import http from 'request-promise';
let server = express();
server.get('/', async function(request, response) {
let result = await http('http://www.google.com');
response.send(result);
});
.babelrc:
{
"presets": [
"es2015",
"node5",
"stage-0"
],
"plugins": [
"transform-runtime"
]
}
和webpack.config.js:
module.exports = {
entry: [
'babel-polyfill',
'./src/server.js'
],
output: {
path: __dirname + '/dist',
filename: 'server_bundle.js'
},
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
test: /\.jsx?$/,
include: __dirname + '/src',
loader: 'babel-loader'
}
]
}
};
我看到了類似的問題在這裏,但它有一個不同的錯誤消息,並已修復巴貝爾:主: ES7 async await functions with babel-loader not working