express中无法使用ES6。

express中无法使用ES6。
在静态文件中es6是被解析了的,在webpack->module->loaders(通过babel- loader)

 test: /.js|jsx$/, loader: "babel", exclude:/node_modules/,

但是在服务端的文件夹中无法识别报错:ReferenceError: promise is not defined

new promise=>{ mongodb.open }.thenfunction db { return db.collectionposts; }.thenfunction collection { let query = {}; if name{ query.name = name } return collection.findquery.sort{time:-1} .toArray }.thendocs=>{ return callbacknull,docs }.catchfunction err { mongodb.close; return callbackerr }; 

以下文件是我的依赖:

 "dependencies": { "babel-loader": "~5.3.2", "babel-preset-es2015": "^6.14.0", "babel-preset-react": "^6.11.1", "babel-preset-stage-0": "latest", "body-parser": "~1.15.1", "bundle-loader": "^0.5.4", "jquery" : "latest", "co-body": "latest", "co-views": "~0.2.0", "cookie-parser": "~1.4.3", "cross-env": "latest", "css-loader": "~0.23.0", "debug": "~2.2.0", "ejs": "~2.4.1", "express": "~4.13.4", "file-loader": "~0.8.5", "json-loader": "^0.5.4", "jsx-loader": "~0.13.2", "morgan": "~1.7.0", "node-sass": "^3.4.2", "ramda": "latest", "raw-loader": "~0.5.1", "react": "~0.14.2", "react-dom": "~0.14.2", "react-router": "latest", "reload": "latest", "sass-loader": "~3.0.0", "serve-favicon": "~2.3.0", "style-loader": "~0.13.0", "supervisor": "latest", "url-loader": "~0.5.6", "webpack": "~1.12.6", "webpack-dev-server": "~1.12.1", "webpack-require-http": "latest", "mongodb": "latest", "express-session": "latest", "connect-mongo": "latest", "connect-flash": "0.1.1" }, "devDependencies": { "babel-cli": "^6.14.0", "babel-core": "^6.14.0", "babel-preset-react-hmre": "^1.1.1", "babel-preset-stage-2": "^6.13.0" } 

并且在根目录下已经添加了.babellrc文件也没有用,依然报错

 { "presets": ["es2015"]
} 

求大神指点一二~~!

试一试把promise首字母大写?node环境应该是直接支持Promise对象的


use strict;

发表评论

电子邮件地址不会被公开。 必填项已用*标注