-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read property 'path' of undefined #41
Comments
Update: I have managed to fix this by providing the route with a name key, you may wan't to update the custom-routes example. |
Hi, thanks for your feedback. |
@alexchopin I'm getting this error again when using the auth-routes demo combined the hidden pages feature, I've replicated it in my own project. It seems that running node server.js throws a path error in vue-router, but running the nuxt command has no errors. I've tried running nuxt build before starting server.js to see if that fixed it but it doesn't. Here is an example: nuxt.config.js module.exports = {
router: {
routes: [
{name: 'demo', path: '/demo/:foo', component: 'pages/_demo'}
]
}
} Example router-link <template>
<div>
<router-link :to="{name: 'demo', params: {foo: 'bar'}}">
Demo Link
</router-link>
</div>
</template> package.json {
"name": "auth-routes",
"description": "",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"express-session": "^1.14.2",
"nuxt": "latest",
"whatwg-fetch": "^2.0.1"
},
"scripts": {
"dev": "node server.js",
"build": "nuxt build",
"start": "NODE_ENV=production node server.js"
}
}
Running the following throws the path error
Running this throws NO error
Here is the exact error
I've tested on both Windows and Mac, both running Node 7.0.1, both has the same error |
Hi @antcook Can you show us your server.js file when you're requiring Nuxt and instantiating it please? |
Using the server.js from the custom-routes example throws the error, and I have also tried starting a fresh project with the following server.js but still throws the same error: const Nuxt = require('nuxt')
const bodyParser = require('body-parser')
const session = require('express-session')
const app = require('express')()
// Body parser, to access req.body
app.use(bodyParser.json())
// Sessions to create req.session
app.use(session({
secret: 'super-secret-key',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
}))
// We instantiate Nuxt.js with the options
const isProd = process.env.NODE_ENV === 'production'
const nuxt = new Nuxt({ dev: !isProd })
// No build in production
const promise = (isProd ? Promise.resolve() : nuxt.build())
promise.then(() => {
app.use(nuxt.render)
app.listen(3000)
console.log('Server is listening on http://localhost:3000')
})
.catch((error) => {
console.error(error)
process.exit(1)
}) |
Can you check in the node_modules/nuxt/package.json which version is it? Sorry about this |
No problem, the version is 0.8.3 |
Hi, const Nuxt = require('nuxt')
const bodyParser = require('body-parser')
const session = require('express-session')
const app = require('express')()
// Body parser, to access req.body
app.use(bodyParser.json())
// Sessions to create req.session
app.use(session({
secret: 'super-secret-key',
resave: false,
saveUninitialized: false,
cookie: { maxAge: 60000 }
}))
// POST /api/login to log in the user and add him to the req.session.authUser
app.post('/api/login', function (req, res) {
if (req.body.username === 'demo' && req.body.password === 'demo') {
req.session.authUser = { username: 'demo' }
return res.json({ username: 'demo' })
}
res.status(401).json({ error: 'Bad credentials' })
})
// POST /api/logout to log out the user and remove it from the req.session
app.post('/api/logout', function (req, res) {
delete req.session.authUser
res.json({ ok: true })
})
// We instantiate Nuxt.js with the options
const isProd = process.env.NODE_ENV === 'production'
let config = require('./nuxt.config.js')
config.dev = !isProd
const nuxt = new Nuxt(config)
// No build in production
const promise = (isProd ? Promise.resolve() : nuxt.build())
promise.then(() => {
app.use(nuxt.render)
app.listen(3000)
console.log('Server is listening on http://localhost:3000')
})
.catch((error) => {
console.error(error)
process.exit(1)
}) |
Thank you so much for your time! That did the trick :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
When I try to run the provided custom-routes example, I get the following error. I've also been able to replicate the bug in my own project by trying to use the hidden pages feature when defining routes.
I'm running Node version v6.9.1 on Windows 10.
The text was updated successfully, but these errors were encountered: