启动服务报错如下:
Last login: Wed Nov :: on ttys000
localhost:~ sipeng$ cd /Users/sipeng/Desktop/彭思/2017年学习/Node/myblog
localhost:myblog sipeng$ node /Users/sipeng/Desktop/彭思/2017年学习/Node/myblog/index.js
/Users/sipeng/Desktop/彭思/2017年学习/Node/myblog/models/posts.js:
(function (exports, require, module, __filename, __dirname) { import { populate } from 'mongolass/lib/plugins';
^^^^^^ SyntaxError: Unexpected token import
at createScript (vm.js::)
at Object.runInThisContext (vm.js::)
at Module._compile (module.js::)
at Object.Module._extensions..js (module.js::)
at Module.load (module.js::)
at tryModuleLoad (module.js::)
at Function.Module._load (module.js::)
at Module.require (module.js::)
at require (internal/module.js::)
at Object.<anonymous> (/Users/sipeng/Desktop/彭思/2017年学习/Node/myblog/routes/posts.js::)
at Module._compile (module.js::)
at Object.Module._extensions..js (module.js::)
at Module.load (module.js::)
at tryModuleLoad (module.js::)
at Function.Module._load (module.js::)
at Module.require (module.js::)
报错原因:
Node.js不支持import导入第三方框架,使用require导入即可。
// import { populate } from 'mongolass/lib/plugins';
const populate = require('mongolass/lib/plugins')
const marked = require('marked')
const Post = require('../lib/mongo').Post