express-vue
express-vue copied to clipboard
SyntaxError: Unexpected token export
I followed ReadMe and starter pack to get this.
Description of Issue
My app.js
.
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var helmet = require('helmet');
var session = require('express-session');
var minify = require('express-minify');
var auth = require('http-auth');
var compression = require('compression');
var expressVue = require("express-vue");
var app = express();
var vueOptions = {
rootPath: path.join(__dirname, "routes")
}
var expressVueMiddleware = expressVue.init(vueOptions);
app.use(expressVueMiddleware);
/**
* Configuration
*/
app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({
secret: '4f5ef4r52rf1re5f24r1efsf',
resave: false,
saveUninitialized: true,
cookie: true
}));
var basic = auth.basic({
file: __dirname + "/ctrl/secure.htpasswd"
});
var router = express.Router();
app.use('/', router);
module.require('./routes/index')(router);
app.listen(3000, () => {
console.log('App listening on port 3000');
});
module.exports = app;
My routing index file
.
module.exports = (router) => {
router.get('/', (req, res, next) => {
const data = {
title: 'Alex'
};
req.vueOptions = {
head: {
title: 'Page Title'
}
}
res.renderVue('home.vue', data, req.vueOptions);
})
};
My home.vue
file.
<template>
<div>
<h1>{{title}}</h1>
<p>Alex</p>
</div>
</template>
<script>
export default {
data: function () {
return {
title: 'Alex'
}
}
}
</script>
Stack Trace / Console Log
App listening on port 3000
Error Precaching
filePath -> /home/alex/Projects/slowin-killer.fr/routes/home.vue
-------
SyntaxError: Unexpected token export
Additional Comments
Am i missing something ?
i just pulled the starter - did npm install
and npm start
- it works fine for me - what version of node are you using? im on 8.11.3 and works with no issues - although previously I have seen issues with 'flow' stuff that was left in the code - i expected to hit those problems when i cloned the repo again but didnt so they shouldnt be an issue for you either. try cloning again from scratch and see if you run into the same problem.
It might be related to the ES Modules. I had a similar issue and solved it by installing babel-core
and babel-preset-env
.
Follow the steps described here.
Thank you, this is perfecly working with:
npm i -D babel-core babel-preset-env babel-preset-es2015 babel-plugin-transform-runtime
I'm still having problems with babel. I keep getting the same errors as above, but I've already installed @babel/core and @babel/preset-env and have a perfectly configured .babelrc. From what I know, babel-core is different than @babel/core. The second one is more recent. I can't downgrade to es2015 because I am using features from es7 and when I install both babel-core and @babel/core they apparently interfere with each other. Any suggestions on a quick fix?
/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/scope/index.js:867
scope.bindings[name] = info;
^
TypeError: Cannot read property 'bindings' of null
at Scope.moveBindingTo (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/scope/index.js:867:13)
at convertBlockScopedToVar (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:139:13)
at PluginPass.VariableDeclaration (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:26:9)
at newFn (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/visitors.js:193:21)
at NodePath._call (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/path/context.js:88:12)
at TraversalContext.visitQueue (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/context.js:118:16)
at TraversalContext.visitMultiple (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/context.js:85:17)
at TraversalContext.visit (/Users/darrenrahnemoon/Projects/Projects/Halliday/web/node_modules/@babel/traverse/lib/context.js:144:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] server: `node index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] server script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/darrenrahnemoon/.npm/_logs/2019-02-18T07_11_44_911Z-debug.log