This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
bug with require #1694
Labels
Comments
Strange behavior. When you move require('UserFactory') inside getAdminUser functtion body, it works. |
yep, that's my hack for now. But I suppose there may be some troubles too |
This is by design. When you have circular require() calls, a module might not be done being executed when it is returned. Consider this: // a.js
console.log("a starting")
exports.done = false
var b = require("./b.js")
console.log("in a, b.done = %j", b.done)
exports.done = true
console.log("a done") // b.js
console.log("b starting")
exports.done = false
var a = require("./a.js")
console.log("in b, a.done = %j", a.done)
exports.done = true
console.log("b done") // main.js
console.log("main starting")
var a = require("./a.js")
var b = require("./b.js")
console.log("in main, a.done=%j, b.done=%j", a.done, b.done)
Todo: Add this to the module docs. |
ghost
assigned isaacs
Sep 13, 2011
Thanks for clarifications :) |
lyonplus
pushed a commit
to lyonplus/node
that referenced
this issue
May 22, 2015
PR-URL: nodejs/node#1679 Notable Changes: * win,node-gyp: the delay-load hook for windows addons has now been correctly enabled by default, it had wrongly defaulted to off in the release version of 2.0.0 (Bert Belder) nodejs#1433 * os: tmpdir()'s trailing slash stripping has been refined to fix an issue when the temp directory is at '/'. Also considers which slash is used by the operating system. (cjihrig) nodejs#1673 * tls: default ciphers have been updated to use gcm and aes128 (Mike MacCana) nodejs#1660 * build: v8 snapshots have been re-enabled by default as suggested by the v8 team, since prior security issues have been resolved. This should give some perf improvements to both startup and vm context creation. (Trevor Norris) nodejs#1663 * src: fixed preload modules not working when other flags were used before --require (Yosuke Furukawa) nodejs#1694 * dgram: fixed send()'s callback not being asynchronous (Yosuke Furukawa) nodejs#1313 * readline: emitKeys now keeps buffering data until it has enough to parse. This fixes an issue with parsing split escapes. (Alex Kocharin) * cluster: works now properly emit 'disconnect' to cluser.worker (Oleg Elifantiev) nodejs#1386 events: uncaught errors now provide some context (Evan Lucas) nodejs#1654
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I've got a strange behavior with require when in some cases
require()
at the beginning of the file causesundefined
instead of contents ofexports
object. Lazy require in methods works well in that case (I really hope so).You may see example code here: node-require-bug.
Sorry for my poor English explanation, I hope you'll see everything in example.
The text was updated successfully, but these errors were encountered: