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

service provider register #7

Closed
amirkheirabadi73 opened this issue Oct 8, 2015 · 14 comments
Closed

service provider register #7

amirkheirabadi73 opened this issue Oct 8, 2015 · 14 comments

Comments

@amirkheirabadi73
Copy link

how i can register my provider in app...
when i put

const provider = [
....
    path.join(__dirname, '../providers/Challenge/provider.js')
]

this return error ....

@thetutlage
Copy link
Member

What error is thrown and can you also show how your provider looks

@amirkheirabadi73
Copy link
Author

this is tace

error: uncaughtException: Unexpected identifier 
{ date: 'Thu Oct 08 2015 10:32:32 GMT+0330 (IRST)',
  process: 
   { pid: 11489,
     uid: 1000,
     gid: 100,
     cwd: '/home/amir/Desktop/test',
     execPath: '/home/amir/.nvm/versions/io.js/v3.3.1/bin/iojs',
     version: 'v3.3.1',
     argv: 
      [ '/home/amir/.nvm/versions/io.js/v3.3.1/bin/iojs',
        '/home/amir/Desktop/test/server.js' ],
     memoryUsage: { rss: 32239616, heapTotal: 16486912, heapUsed: 8283336 } },
  os: { loadavg: [ 0.8828125, 0.9150390625, 1.375 ], uptime: 1798 },
  trace: 
   [ { column: 16,
       file: 'vm.js',
       function: 'exports.runInThisContext',
       line: 53,
       method: 'runInThisContext',
       native: false },
     { column: 25,
       file: 'module.js',
       function: 'Module._compile',
       line: 413,
       method: '_compile',
       native: false },
     { column: 10,
       file: 'module.js',
       function: 'Object.Module._extensions..js',
       line: 448,
       method: 'Module._extensions..js',
       native: false },
     { column: 32,
       file: 'module.js',
       function: 'Module.load',
       line: 355,
       method: 'load',
       native: false },
     { column: 12,
       file: 'module.js',
       function: 'Function.Module._load',
       line: 310,
       method: 'Module._load',
       native: false },
     { column: 17,
       file: 'module.js',
       function: 'Module.require',
       line: 365,
       method: 'require',
       native: false },
     { column: 17,
       file: 'module.js',
       function: 'require',
       line: 384,
       method: null,
       native: false },
     { column: 13,
       file: '/home/amir/Desktop/test/bootstrap/http.js',
       function: '',
       line: 14,
       method: null,
       native: false },
     { column: 26,
       file: 'module.js',
       function: 'Module._compile',
       line: 430,
       method: '_compile',
       native: false },
     { column: 10,
       file: 'module.js',
       function: 'Object.Module._extensions..js',
       line: 448,
       method: 'Module._extensions..js',
       native: false } ],
  stack: 
   [ 'SyntaxError: Unexpected identifier',
     '    at exports.runInThisContext (vm.js:53:16)',
     '    at Module._compile (module.js:413:25)',
     '    at Object.Module._extensions..js (module.js:448:10)',
     '    at Module.load (module.js:355:32)',
     '    at Function.Module._load (module.js:310:12)',
     '    at Module.require (module.js:365:17)',
     '    at require (module.js:384:17)',
     '    at Object.<anonymous> (/home/amir/Desktop/test/bootstrap/http.js:14:13)',
     '    at Module._compile (module.js:430:26)',
     '    at Object.Module._extensions..js (module.js:448:10)' ] }

@amirkheirabadi73
Copy link
Author

sorry ...
/provider/Challenge/provier.js

'use strict'

const ServiceProvider = require('adonis-fold').ServiceProvider
const Challenge = require('./Challenge')

class ChallengeProvider extends ServiceProvider {

    * register() {

        this.app.bind('Challenge/Challenge', function() {
            return new Challenge()
        })

    }

}

@thetutlage
Copy link
Member

There is some syntax error in your Challenge.js file.

Here's is the problem

The reason you are not able to see the exact error is , v8 removes the filename from error stack and node is not able to get it back. Check out this thread
nodejs/node-v0.x-archive#3452

@amirkheirabadi73
Copy link
Author

my challenge.js

'use strict'


class Challenge {

    * getTime() {
        return new Date().getTime;
    }

}


module.exports = Challenge

i don't think the related to my class

@thetutlage
Copy link
Member

There is some syntax error as the stack trace states. I created a quick repo with your service provider and it works fine.

Try cloning this https://github.com/thetutlage/adonis-issue-7

Not getting the filename for error is inconvenience but that is by v8 itself.

@amirkheirabadi73
Copy link
Author

wwwwow thx
but also data that my function return in challenge class is empty array in homecontroller ...

@thetutlage
Copy link
Member

Any chance of sharing your code repo , or a copy of your code ?

@amirkheirabadi73
Copy link
Author

no also
https://github.com/thetutlage/adonis-issue-7
has this error ...

my homecontroller

'use strict'

const ch = use('Challenge/Challenge')

class HomeController {

    * index(request, response) {
        return ch.getTime()
    }
}

module.exports = HomeController

@thetutlage
Copy link
Member

https://github.com/thetutlage/adonis-issue-7 works fine for me and as it is a syntax error it will have nothing to do with version of node or npm

@thetutlage
Copy link
Member

Also getTime is generator function , so you have to prepend it with yield

@amirkheirabadi73
Copy link
Author

thx ... every thing work fine ....

@thetutlage
Copy link
Member

👍

@lock
Copy link

lock bot commented Mar 12, 2020

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.

@lock lock bot locked and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants