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.

Error when starting rest-hapi plugin: Cannot set property 'Promise' of undefined

See original GitHub issue

I tried for two hours to start rest-hapi demo project, but failed. Maybe I missed something. Would appreciate help. When node api.js get error:

TypeError: Cannot set property 'Promise' of undefined
    at module.exports (/Users/mike/projects/a_learn/rest-hapi_test/node_modules/rest-hapi/components/mongoose-init.js:11:20)
    at Object.register (/Users/mike/projects/a_learn/rest-hapi_test/node_modules/rest-hapi/rest-hapi.js:67:57)
    at internals.Server.register (/Users/mike/projects/a_learn/rest-hapi_test/node_modules/hapi/lib/server.js:427:35)
    at api (/Users/mike/projects/a_learn/rest-hapi_test/api.js:31:18)
    at Object.<anonymous> (/Users/mike/projects/a_learn/rest-hapi_test/api.js:41:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

My package.json

{
  "name": "rest-hapi_test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "hapi": "^17.4.0",
    "mongoose": "^5.1.0",
    "rest-hapi": "^0.43.1"
  }
}

My api.js

'use strict';

let Hapi = require('hapi');
let mongoose = require('mongoose');
let restHapi = require('rest-hapi');

async function api(){

    const server = new Hapi.Server(restHapi.config.server.connection);

    const plugins = [
        {
            name: 'restHapi',
            version: '1.0.0',
            register: restHapi.register,
            options: {
                mongoose: mongoose
            }
        }
    ]

    await server.register(plugins);
    await server.start();
    console.log(`Server running at: ${server.info.uri}`); // eslint-disable-line
}

process.on('unhandledRejection', (err) => {
    console.error(err); // eslint-disable-line
    process.exit(1);
});

api();

P.S. Also tried with canonical example from docs it does not work as well.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
JKHeadleycommented, May 15, 2018

@klishevich thanks for the link. So the issue here is that you are trying to use hapi v17, which is currently incompatible with rest-hapi. I’m in the process of updating to v17, but in the meantime if you would like to use rest-hapi you will need to work with hapi v16. You can find the v16 docs here. Hope this helps!

0reactions
klishevichcommented, May 27, 2018

@JKHeadley thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[bug] TypeError: Cannot set property '' of undefined · Issue #316
Hi, I have a bug with es6-promise in my react-native project an I am not sure how to solve it. I am even...
Read more >
Uncaught TypeError: Cannot set property 'plugin' of undefined
I have no idea where you got the script from, but the function it is breaking in hashes window.location.hostname to perform that action....
Read more >
21.1.0 API Reference - hapi.dev
When false , indicates that the listener will be started manually outside the framework. Cannot be set to false along with a port...
Read more >
Cannot set property 'value' of undefined - WordPress.org
I have noticed that the plugin seems to be throwing a JS error: Uncaught (in promise) TypeError: Cannot set property 'value' of undefined...
Read more >
hapi — How to Fix “handler method did not return a value, a ...
The error message means that you returned undefined or null from your route handler. Hapi v17 expects you to return either a value,...
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