aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

ValidationEngine is undefined #99

Closed alsoicode closed 8 years ago

alsoicode commented 8 years ago

I'm working from a CLI-generated project. I've included the module and dependencies in my aurelia.json bundle as:

{
  "name": "aurelia-validation",
  "path": "../node_modules/aurelia-validation/dist/amd",
  "main": "aurelia-validation"
 },
 {
  "name": "aurelia-validatejs",
  "path": "../node_modules/aurelia-validatejs/dist/amd",
  "main": "aurelia-validatejs"
 },
 {
   "name": "validate.js",
   "path": "../node_modules/validate.js/",
   "main": "validate"
 }

and bundling is successful, however, when importing ValidationEngine I get undefined:

import { ValidationEngine } from 'aurelia-validatejs';

class Inquiry { . . . }

export class Inquire {
  constructor() {
    this.inquiry = new Inquiry();
    this.reporter = ValidationEngine.getValidationReporter(this.inquiry);
    . . .
  }
}

What am I doing wrong? I'm following the "decorators" sample code at: https://github.com/aurelia/validatejs/blob/master/sample/src/decorators.js

Stack Trace from Chrome:

vendor-bundle.js:12290 ERROR [app-router] Error: Error invoking Inquire. Check the inner error for details.
------------------------------------------------
Inner Error:
Message: Cannot read property 'getValidationReporter' of undefined
Inner Error Stack:
TypeError: Cannot read property 'getValidationReporter' of undefined
    at new Inquire (http://localhost:9000/scripts/app-bundle.js:227:56)
    at Object.invoke (http://localhost:9000/scripts/vendor-bundle.js:9520:14)
    at InvocationHandler.invoke (http://localhost:9000/scripts/vendor-bundle.js:9491:168)
    at Container.invoke (http://localhost:9000/scripts/vendor-bundle.js:9755:25)
    at StrategyResolver.get (http://localhost:9000/scripts/vendor-bundle.js:9293:37)
    at Container.get (http://localhost:9000/scripts/vendor-bundle.js:9692:23)
    at http://localhost:9000/scripts/vendor-bundle.js:21029:73
    at tryCatcher (http://localhost:9000/scripts/vendor-bundle.js:3297:23)
    at Promise._settlePromiseFromHandler (http://localhost:9000/scripts/vendor-bundle.js:2505:31)
    at Promise._settlePromise (http://localhost:9000/scripts/vendor-bundle.js:2562:18)
    at Promise._settlePromise0 (http://localhost:9000/scripts/vendor-bundle.js:2607:10)
    at Promise._settlePromises (http://localhost:9000/scripts/vendor-bundle.js:2686:18)
    at http://localhost:9000/scripts/vendor-bundle.js:153:25
End Inner Error Stack
------------------------------------------------

I also get the same result when using the ESNext Skeleton project.

alsoicode commented 8 years ago

Closing. Following the example at: http://blog.durandal.io/2016/06/14/new-validation-alpha-is-here/ got it working for me.