Comments (10)
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.
from nuxt.
Hi, thanks for your feedback.
The example is fixed now.
from nuxt.
@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
npm run dev
npm start
Running this throws NO error
npm build
Here is the exact error
Vue.js error
TypeError: Cannot read property 'path' of undefined
at VueRouter.match (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-router\dist\vue-router.common.js:1135:44)
at VueRouter.resolve (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-router\dist\vue-router.common.js:2037:23)
at Proxy.render (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-router\dist\vue-router.common.js:300:22)
at VueComponent.Vue._render (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue\dist\vue.runtime.common.js:2925:22)
at renderComponent (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-server-renderer\build.js:5888:25)
at renderNode (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-server-renderer\build.js:5871:7)
at next (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-server-renderer\build.js:6007:9)
at cachedWrite (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-server-renderer\build.js:36:9)
at renderElement (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-server-renderer\build.js:5931:5)
at renderNode (C:\Users\Anthony\Desktop\auth-routes\node_modules\vue-server-renderer\build.js:5875:7)
I've tested on both Windows and Mac, both running Node 7.0.1, both has the same error
from nuxt.
Hi @antcook
Can you show us your server.js file when you're requiring Nuxt and instantiating it please?
from nuxt.
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)
})
from nuxt.
Can you check in the node_modules/nuxt/package.json which version is it?
Sorry about this
from nuxt.
No problem, the version is 0.8.3
from nuxt.
Hi,
It's because you need to import your nuxt.config.js before instantiate Nuxt in your server.js.
We still need to complete the documentation, sorry about that.
You can see this example :
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)
})
from nuxt.
Thank you so much for your time! That did the trick :)
from nuxt.
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.
from nuxt.
Related Issues (20)
- HMR doesn't work on pages that are added to .nuxtignore file HOT 6
- updating of experimental options HOT 3
- Option to install layer dependencies with --ignore-scripts HOT 2
- `$fetch` interceptor not modifying the retried request when a body is present HOT 5
- How can we integrate AMP ( Accelerated Mobile pages) In nuxt 3.8 ?
- How override plugins from Nuxt Layer in app? HOT 3
- Why can't the server run? "vue-router": "^4.3.2","vue": "^3.4.26", HOT 2
- How to automatically reference enum types?Why can't implicit references be used? HOT 3
- Styles get added both inline and by reference and precede JS files HOT 2
- A page re-rendering and page deletion composable
- Infinite redirection when using qs after nuxt 3.11 HOT 3
- `Failed to execute 'insertBefore' on 'Node':` with useAsyncData and Pre-Rendering HOT 8
- Improve ignorePrefix JSDoc HOT 2
- No export named 'consola' after upgrading to `v3.11.2` HOT 3
- createError will be requested twice in the get request HOT 2
- Doesn't find indirect dependency of module when using pnpm
- `<ServerOnly>` component (to render markup only once) HOT 3
- Suggestion for new composables: `useResponseHeader(s)` similar to existing `useRequestHeader` composable HOT 1
- SSG: Payload doesn't prefetched when link contains hash property HOT 1
- onUploadProgress on $fetch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.