Skip to content
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 'isNextDevCommand' of undefined #13466

Closed
j-quelly opened this issue May 27, 2020 · 10 comments · Fixed by #13539
Closed

TypeError: Cannot read property 'isNextDevCommand' of undefined #13466

j-quelly opened this issue May 27, 2020 · 10 comments · Fixed by #13539
Labels
good first issue Easy to fix issues, good for newcomers please add a complete reproduction Please add a complete reproduction.

Comments

@j-quelly
Copy link

j-quelly commented May 27, 2020

Bug report

Describe the bug

TypeError: Cannot read property 'isNextDevCommand' of undefined options in createServer() do not seem to have the isNextDevCommand property

To Reproduce

  1. start custom server
  2. navigate to /
  3. See error

Expected behavior

Not this

Screenshots

Screen Shot 2020-05-27 at 12 56 41 PM

System information

  • OS: macOS
  • Browser (if applies) chrome
  • Version of Next.js: 9.3.2
  • Version of Node.js: v12.16.2

Additional context

@Timer
Copy link
Member

Timer commented May 27, 2020

Sounds like the next instance is being instantiated incorrectly.

Look for:

const app = next()

And be sure you're passing dev as shown in our examples:

const app = next({ dev: boolean })

Relevant examples:

const app = next({ dev })

const app = next({ dev })

Happy to take a PR giving a better error message when there's bad user input.

@Timer Timer added good first issue Easy to fix issues, good for newcomers help wanted labels May 27, 2020
@j-quelly
Copy link
Author

Hey thanks Timer, my server is as follows:

Do you see anything that looks wrong here?

const cacheableResponse = require('cacheable-response');
const express = require('express');
const next = require('next');
const cookieParser = require('cookie-parser');
const { uuid } = require('uuidv4');

const port = 8001;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();

const ssrCache = cacheableResponse({
  ttl: 1000 * 60 * 60, // 1hour
  get: async ({ req, res, pagePath, queryParams }) => {
    const data = await app.renderToHTML(req, res, pagePath, queryParams);

    // Add here custom logic for when you do not want to cache the page, for
    // example when the page returns a 404 status code:
    if (res.statusCode === 404) {
      res.end(data);
      return;
    }

    return { data };
  },
  send: ({ data, res }) => res.send(data),
});

const SSRController = ({ pagePath }, req, res) => {
  const {
    context: { isProduction },
  } = req;

  if (isProduction) {
    return ssrCache({ req, res, pagePath });
  }

  return app.render(req, res, pagePath, req.query);
};

app.prepare().then(() => {
  const server = express();
  server.use(cookieParser());

  server.get('/', SSRController.bind(null, { pagePath: '/' }));

  // handle all other requests
  // in dev mode this will always recompile
  // in production this will either return a precompiled page via renderToHTML
  // or will compile the requested route if it invokes methods that require a server
  // the SSR pages that resolve here are not cached
  // more here: https://gist.github.com/timruffles/153a04f6956399907d90d73af0093e9f
  server.get('*', (req, res) => handle(req, res));

  // error handler for express
  // this does not catch errors thrown in next.js
  server.use((err, req, res, next) => {
    const {
      context: { isDevelopment },
    } = req;

    if (err) {
      const scope = {
        sid: req.cookies.sid,
        method: req.method,
        url: req.path,
        query: req.query,
        headers: req.headers,
        params: req.params,
        msg: err.message,
        timestamp: new Date(),
        err,
      };
      if (!isDevelopment) {
        plogger.error(err.message || 'error', scope);
      } else {
        console.error(err.message || 'error', scope);
      }
    }

    next();
  });

  server.listen(port, err => {
    if (err) throw err;
  });
});

@Timer
Copy link
Member

Timer commented May 28, 2020

Without a full demo I can't help trace this down!

@todortotev
Copy link
Contributor

Happy to take a PR giving a better error message when there's bad user input.

If I understand correctly, you want a better error message when the user passes any variable that isn't a boolean, correct?

Cause right now I can pass an integer, string, array, or even an arrow function and I won't see any warnings at all.

Screenshot 2020-05-28 at 10 46 04

@j-quelly
Copy link
Author

@todortotev I'm not asking for better error message.

I'm receiving this error message and I cannot figure out why.

@Timer You want to see a demo of the server failing to start and throwing the error message I attached as a screenshot? Happy to attach a gif, but I don't see what value that adds?

@moh12594
Copy link
Contributor

moh12594 commented May 28, 2020

@Timer I opened this PR to have a better message error, it seems like the error happens when the parameter isn't defined.

@j-quelly
Copy link
Author

What just happened? Did any of you read this thread?

@kodiakhq kodiakhq bot closed this as completed in #13539 Jun 3, 2020
kodiakhq bot pushed a commit that referenced this issue Jun 3, 2020
**First, apologies for a second PR on the same issue but I was working on this already so I thought I'd push it and let you decide which you want to merge.**

The PR is related to [13466](#13466).

Based on my research, the error happens if the options are empty, null, or undefined. That's why I have decided that the most proper check would be using the! post-fix expression operator may assert that its operand is non-null and non-undefined. ``if (options == null)``

(Optional)
I have also added a warning, which warns the user if the passed "dev" variable is not a boolean.

It's my first PR on the "packages" part of the repo so I'd be glad to receive all kinds of critics. If you want me to change or remove anything, I'm open to suggestions.

---

Fixes #13466
@timneutkens timneutkens reopened this Jun 3, 2020
@timneutkens
Copy link
Member

@Timer You want to see a demo of the server failing to start and throwing the error message I attached as a screenshot? Happy to attach a gif, but I don't see what value that adds?

A full github repository would help

@Timer Timer removed the help wanted label Jun 3, 2020
rokinsky pushed a commit to rokinsky/next.js that referenced this issue Jul 11, 2020
**First, apologies for a second PR on the same issue but I was working on this already so I thought I'd push it and let you decide which you want to merge.**

The PR is related to [13466](vercel#13466).

Based on my research, the error happens if the options are empty, null, or undefined. That's why I have decided that the most proper check would be using the! post-fix expression operator may assert that its operand is non-null and non-undefined. ``if (options == null)``

(Optional)
I have also added a warning, which warns the user if the passed "dev" variable is not a boolean.

It's my first PR on the "packages" part of the repo so I'd be glad to receive all kinds of critics. If you want me to change or remove anything, I'm open to suggestions.

---

Fixes vercel#13466
@balazsorban44 balazsorban44 added the please add a complete reproduction Please add a complete reproduction. label Jan 12, 2022
@balazsorban44
Copy link
Member

This issue has been automatically closed after 30 days of inactivity with no reproduction. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers please add a complete reproduction Please add a complete reproduction.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants