Undefined type at ts - express application with mongoose #2

Closed
morgoth opened this Issue Apr 10, 2012 · 4 comments

Projects

None yet

4 participants

@morgoth
morgoth commented Apr 10, 2012

Hi.

I cannot run tests that are requiring timekeeper. I'm using mongoose in express application.
Strange thing is that other developers, working on the same application, don't have this problem.
My machine:
Linux ibm 3.2.0-22-generic #35-Ubuntu SMP Tue Apr 3 18:33:15 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Error:

TypeError: Undefined type at `ts`
  Did you try nesting Schemas? You can only nest using refs or arrays.
    at Function.interpretAsType (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/lib/schema.js:223:11)
    at Schema.path (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/lib/schema.js:181:29)
    at Schema.add (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/lib/schema.js:117:12)
    at new Schema (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/lib/schema.js:38:10)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/lib/schemadefault.js:14:29)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/lib/index.js:10:22)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/node_modules/mongoose/index.js:7:18)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/app/models/courier.js:1:78)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/test/helpers/factories/courier.js:3:15)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at require_directory (/home/wojtek/Projects/tiramizoo-api/node_modules/directory/index.js:44:16)
    at directory (/home/wojtek/Projects/tiramizoo-api/node_modules/directory/index.js:26:12)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/test/helpers/factories/index.js:30:20)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/test/models/rate_test.js:1:77)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at require_directory (/home/wojtek/Projects/tiramizoo-api/node_modules/directory/index.js:44:16)
    at directory (/home/wojtek/Projects/tiramizoo-api/node_modules/directory/index.js:26:12)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/test/models/index.js:1:82)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/wojtek/Projects/tiramizoo-api/test/index.js:2:1)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at /home/wojtek/.nvm/v0.6.15/lib/node_modules/mocha/bin/_mocha:261:27
    at Array.forEach (native)
    at load (/home/wojtek/.nvm/v0.6.15/lib/node_modules/mocha/bin/_mocha:258:9)
    at Object.<anonymous> (/home/wojtek/.nvm/v0.6.15/lib/node_modules/mocha/bin/_mocha:249:1)
    at Module._compile (module.js:441:26)
    at Object..js (module.js:459:10)
    at Module.load (module.js:348:31)
    at Function._load (module.js:308:12)
    at Array.0 (module.js:479:10)
    at EventEmitter._tickCallback (node.js:192:40)

Anybody had similar problem?

Owner
vesln commented Apr 20, 2012

Hm, strange. Can you please provide the timekeeper version and the code that breaks it. Thanks!

morgoth commented Apr 26, 2012

After some code rewrite/refactoring this problem disappeared. This is strange for me, because there wasn't any code related to timekeeper or mongoose in this change. I have no idea what caused this error.

@vesln vesln closed this Apr 26, 2012
jesperp commented May 11, 2012

Hey morgoth, I'm using mongoose+express not timekeeper, but I got a similar error ("Undefined type at ...") and it was because in my test file i did:

   , models = require('../models')
   , app = require('../app').app

While I had accidentally left this in models.js

   , app = require('../app')

Not exactly sure why but it seems to revolve around these particular imports. Solution: don't include app in models.js

Contributor
jpallen commented Aug 7, 2012

This happens when you have a Date in your Mongoose schema which is called after timekeeper has been included. Timekeeper replaces Date with its own class, FakeDate, but Mongoose doesn't understand what to do with this.

I have created a pull request for timekeeper which solves this issue by not replacing Date with FakeDate until you actually need it, which will most likely be after your have loaded your Mongoose schemas so that it won't interfere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment