Nuxt.js: Need better way to logs error on Server Error page?

Created on 8 Nov 2017  路  21Comments  路  Source: nuxt/nuxt.js

All I get is the below image, nothing else.

How can I know what went wrong?

screen shot 2017-11-08 at 2 55 01 pm

The following is my setup.

const cors = require('cors')({ origin: true })
const express = require('express')
const functions = require('firebase-functions')
const fs = require('fs')
const path = require('path')
const { Nuxt } = require('nuxt')

const nuxtDir = path.resolve('.', 'nuxt')
if (fs.existsSync(nuxtDir)) {
  console.log('Nuxt directory exists.', nuxtDir)
} else {
  console.error('Nuxt directory does not exists.', nuxtDir)
}

const app = express()
const nuxt = new Nuxt({ dev: false, buildDir: 'nuxt' })

app.use(cors)
app.use(nuxt.render)

exports.render = functions.https.onRequest(app)

It works if i run firebase serve --only functions,hosting locally
But doesn't when i deploy it to firebase and show the above image.

This question is available on Nuxt.js community (#c1816)
question

Most helpful comment

Please don't close this issue, debug: true is not a good solution because shows the error at the browser, we need an way to see the log without exposing the code!

All 21 comments

Same question here but with different server code. How do I log the errors?
Doing this I can see the errors on the page, but I don't want to do that in production.

module.exports = {
  debug: true
}
const { Nuxt, Builder } = require('nuxt')

const https = require('https')
const fs = require('fs')
const isProd = (process.env.NODE_ENV === 'production')
const port = process.env.PORT || 3000

// We instantiate nuxt.js with the options
const config = require('./nuxt.config.js')
config.dev = !isProd
const nuxt = new Nuxt(config)

// Render every route with Nuxt.js

// Build only in dev mode with hot-reloading
if (config.dev) {
  new Builder(nuxt).build()
  .then(listen)
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })
}
else {
  listen()
}

function listen() {
    const options = {
key: fs.readFileSync('/home/certs/localhost.key'),
cert: fs.readFileSync('/home/certs/localhost.crt')
};
  // Listen the server
// Create the server
https
.createServer(options, nuxt.render)
.listen(port)
  console.log('Server listening on `localhost:' + port + '`.')
}

Where is the logs?

I also addressed the same problem.
adding the following code to nuxt.config.js, we were able to display error details in production( or staging project) as well.
@atmar thanks for the example!
( not native english :) )

process.env.DEBUG = 'nuxt:*'

module.exports = {
  debug: true,
...

error

In my case, I am getting better by adding a module.

yarn add regenerator-runtime
yarn add core-js
...
firebase deploy

@yoidotco do you have a repo that I can take look at?

@BruceHem
It is not yet.
If you have nuxt.config.js in your repository, please add debug: true, to it :)

2017-11-26 22 04 10
2017-11-26 22 03 47

Ok, I can confirm that putting debug: true shows the error.

I had to install all nuxt dependencies manually, somehow specifying just nuxt in package.json is not enough.

Please don't close this issue, debug: true is not a good solution because shows the error at the browser, we need an way to see the log without exposing the code!

This may be able to be use. for firebase functions(SSR).
express-winston + Stackdriver Trace
https://cloud.google.com/nodejs/getting-started/logging-application-events
https://github.com/GoogleCloudPlatform/nodejs-getting-started/blob/master/5-logging/app.js

I'm going to try it out.
If it works, I will publish the source :)

@yoidotco is there any update on this ?

Working well here!

Hey guys, since the latest Nuxt version uses async/await by default (node 8), firebase cloud function will not work since it's still using only node 6. Any workarounds?

@chanlito

I was wondering the same thing. Any luck?

@davidroyer nope

@danieloprado what is the latest on this? Can we close it?

Please don't close it. There is still a need to send the logs to a file instead of having to use
module.exports = {
debug: true
}
to show them on the website itself.

@pi0 @husayt any idea on how to solve this? The trello is archived but I can't see a solution

@pi0 I'm pinging this thread again. This is a really important feature. Even today I had unexplained errors for users and there is no way for me to check. It says "check the logs" but there are no logs and I can't expose debug to true in production, that's a horrible solution

@atmar you could use nuxt/sentry module. Or look at it's code and write same module to send errors to file or to whatever you want to

As @aldarund mentioned, nuxt/sentry should provide all pointers needed for implementing similar functionality.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredreich picture jaredreich  路  3Comments

surmon-china picture surmon-china  路  3Comments

vadimsg picture vadimsg  路  3Comments

bimohxh picture bimohxh  路  3Comments

maicong picture maicong  路  3Comments