Hi I'm using WebStorm latest version to work with Node.js (express.js) frame work. I have set my babel
so that I can use ES6 syntax (for example
import express from "express".
Babel work ok it generate the index.js which contain index.js.map.
The problem is when running the project i still get the error
/usr/local/Cellar/node/7.10.0/bin/node /Volumes/Elements/Learning/Node/Project/NodeWebStorm/bin/www
/Volumes/Elements/Learning/Node/Project/NodeWebStorm/routes/index.js:1
(function (exports, require, module, __filename, __dirname) { import express from "express"
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/Volumes/Elements/Learning/Node/Project/NodeWebStorm/app.js:8:13)
Process finished with exit code 1
Here is my index.js which babel generate. Look ok, i even tried to run it alone with no error
'use strict';
var _express = require('express');
var _express2 = _interopRequireDefault(_express);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// let express = require("express");
var router = _express2.default.Router();
/* GET home page. */
router.get('/', function (req, res, next) {
// res.render('index', { title: 'Express' });
res.render('newindex', { title: 'Hey', message: 'Hello there!' });
});
router.get('/about', function (req, res) {
res.send('what the hell');
});
router.get('/new', function (req, res) {
res.json({ "test": "new value" });
});
router.get('/new/path', function (req, res) {
res.send("what the new");
});
router.get('/newpath', function (req, res) {
res.send('this is new path');
});
router.get('/testpath', function (req, res) {
res.send('what the hell');
});
module.exports = router;
//# sourceMappingURL=index.js.map
The template is from node.js express template from webstorm. Anyone one know how to fix that. Do I need add any additional step. Thanks
via Lê Khánh Vinh
No comments:
Post a Comment