Giter Club home page Giter Club logo

Comments (10)

antcook avatar antcook commented on May 18, 2024

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.

alexchopin avatar alexchopin commented on May 18, 2024

Hi, thanks for your feedback.
The example is fixed now.

from nuxt.

antcook avatar antcook commented on May 18, 2024

@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.

Atinux avatar Atinux commented on May 18, 2024

Hi @antcook

Can you show us your server.js file when you're requiring Nuxt and instantiating it please?

from nuxt.

antcook avatar antcook commented on May 18, 2024

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.

Atinux avatar Atinux commented on May 18, 2024

Can you check in the node_modules/nuxt/package.json which version is it?

Sorry about this

from nuxt.

antcook avatar antcook commented on May 18, 2024

No problem, the version is 0.8.3

from nuxt.

alexchopin avatar alexchopin commented on May 18, 2024

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.

antcook avatar antcook commented on May 18, 2024

Thank you so much for your time! That did the trick :)

from nuxt.

lock avatar lock commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.