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

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

Closed
klishevich opened this issue May 13, 2018 · 5 comments

Comments

@klishevich
Copy link

klishevich commented May 13, 2018

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.

@JKHeadley
Copy link
Owner

Hi @klishevich, the package.json and api.js files you posted don't match the rest-hapi-demo files. Are you sure you posted the right files (the package.json you posted doesn't have a dependency on rest-hapi for instance)? I tested the rest-hapi-demo project and it seems to be working fine.

@klishevich
Copy link
Author

@JKHeadley sorry my bad, copy pasted wrong file. I updated package.json it the issue and this is the link for GitHub repo with my test project - https://github.com/klishevich/a_learn/tree/master/rest-hapi_test

@JKHeadley
Copy link
Owner

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

@JKHeadley
Copy link
Owner

@klishevich rest-hapi v1.0.0 is now available with Hapi 17 support.

@klishevich
Copy link
Author

@JKHeadley thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants