question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use module terminal exceptions. (UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined)

See original GitHub issue

Version

@nuxt/content:1.10.0 nuxt:2.14.6

Steps to reproduce

Configure the ‘@nuxt/content’ module to refresh the page and the terminal reports an error.

Mine is a brand new project.

(node:31206) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at WebSocket.setSocket (/Users/projects/node_modules/ws/lib/websocket.js:162:14)
    at WebSocketServer.completeUpgrade (/Users/projects/node_modules/ws/lib/websocket-server.js:322:8)
    at WebSocketServer.handleUpgrade (/Users/projects/node_modules/ws/lib/websocket-server.js:245:10)
    at WS.handleUpgrade (/Users/projects/node_modules/@nuxt/content/lib/ws.js:21:21)
    at WS.serve (/Users/projects/node_modules/@nuxt/content/lib/ws.js:17:10)
    at /Users/projects/node_modules/@nuxt/content/lib/middleware.js:12:15
    at call (/Users/projects/node_modules/connect/index.js:239:7)
    at next (/Users/projects/node_modules/connect/index.js:183:5)
    at next (/Users/projects/node_modules/connect/index.js:161:14)
    at WebpackBundler.middleware (/Users/projects/node_modules/@nuxt/webpack/dist/webpack.js:5562:5)
(node:31206) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:31206) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Remove the plug-in in the ‘nuxt.config.js’ file, the project is normal.

modules: [
    // https://go.nuxtjs.dev/content  
    // '@nuxt/content',  
],

Server configuration

const Koa = require("koa");
const { Nuxt, Builder } = require("nuxt");

const app = new Koa();
// Import and Set Nuxt
const config = require("../nuxt.config.js");
config.dev = !(app.env === "production");
const env = config.dev ? "dev" : "prod";
const host = "localhost";
const port = "4000";

async function start() {
  // Instantiate nuxt.js
  const nuxt = new Nuxt(config);

  // Build in development
  if (env === "dev") {
    await new Builder(nuxt).build();
  }

  app.use(async ctx => {
    ctx.status = 200;
    ctx.respond = false; // Mark request as handled for Koa
    ctx.req.ctx = ctx; // This might be useful later on, e.g. in nuxtServerInit or with nuxt-stash
    await nuxt.render(ctx.req, ctx.res);
  });

  app.listen(port, host);
  console.log(`Server listening on http://${host}:${port}`);
}

start();

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pangxiejucommented, Oct 27, 2020

Temporarily handle, block’UnhandledPromiseRejectionWarning’ .🤣

 // ./server/index.js
 if (env === "dev") {
    await new Builder(nuxt).build();
    process.on('unhandledRejection', (error) => {});
 }
0reactions
kgrosvenorcommented, Apr 13, 2022

Im getting this error with nuxt in ssr mode, how to fix. Is unhandledRejection the best way to handle it? @danielroe @pangxieju

Read more comments on GitHub >

github_iconTop Results From Across the Web

npm outdated error Cannot read property 'length' of undefined
Here's how I successfully fixed the error after checking 'global' was in outdated.js file. Without any other requirements like brew etc, (type ...
Read more >
Typeerror: Cannot Read Property 'length' of Undefined
The Solution. The simplest fix to this error is to make sure we are defining what we want to compare length to, so...
Read more >
UnhandledPromiseRejectionWarning: TypeError: Cannot read ...
Queries related to “UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined in hogan.js nodejs”.
Read more >
Resolving the JavaScript Promise Error "TypeError: Cannot ...
TypeError - Cannot read property 'then' of undefined is thrown when the caller is expecting a Promise to be returned and instead receives ......
Read more >
Node.js v19.3.0 Documentation
node:buffer module APIs ... Usage; Node-API version matrix; Environment life cycle APIs ... Accessing core Node.js modules; Global uncaught exceptions ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found