-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Sails 1.0.0-33 doesn't boot on Node 8.3.0 when accessing require('sails').config
#4165
Comments
@sadasant Thanks for posting, we'll take a look as soon as possible. For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here. |
@sadasant I haven't been able to reproduce your issue, but in general it's not recommended that you rely on the Sails object while files are being loaded (i.e. outside of the If you're implementing a service that needs some initialization, you might consider changing it to be a hook, which has built-in support for configuration using the Sails app object. If you want to keep it as a service, you have several options, but in general they all revolve around making the service itself a function that returns an object, e.g.:
Then in your app would call All that being said, if you think there's an actual bug here and you can post a link to a repo that reliably reproduces it, we can check it out. How have you test 8.2.0 vs 8.3.0? Are you using |
@sgress454 My friend @sean-clayton will follow up. |
@sgress454 we're also getting this issue:
from this code: module.exports.login = (...params) => login(sails.models.user.login)(...params) Is this not a proper way of referencing a sails model? |
@sean-clayton It is, and again I can't reproduce these issues, so it would really be helpful to have a repo I could check out. I'd also try wiping and re-installing your node modules; especially if you're using NVM there could be some conflicts with global modules. |
@sgress454 I have dug up some more and found what we think is a bug, either in Sails or Node 8.3.0 Here is a reproducible case. I've included our theory and instructions in the project's README.md If you have any questions, please feel free to ask away 😸 |
@sgress454 to be very specific, there seems to be a bug on node 8.3 when a service requires a service that requires sails, which prevents sails.models from working at all. |
@sean-clayton Thanks for the repo. This doesn't appear to have anything to do with services; it looks to me like the issue is that in Node 8.3.0,
you'll get
you do get I'll keep looking into this, but in the meantime, in your specific case, the answer is just to not use |
That's really strange... and worth looking into why it's happening only in Node 8.3.0. Maybe it could be a difference in how dependencies are getting picked up? Like, do we see this same behavior when using |
I just tested my example project and it still has the same error when running with |
hmmm nodejs/node@eb023ef7df (it's unrelated, but it made me notice the |
I'm suspecting it's something to do with this: https://github.com/balderdashy/include-all/blob/0212ddcee652d71fc90edf0d441c56e40f35d956/lib/help-include-all-sync.js#L266-L289 |
@mikermcneil I tried out using the global sails—here's the diff: diff --git a/api/services/Test2Service.js b/api/services/Test2Service.js
index f95a209..45d0250 100644
--- a/api/services/Test2Service.js
+++ b/api/services/Test2Service.js
@@ -1 +1 @@
-let sails = require('sails')
+let sails = sails And I'm getting this error when starting the application with
|
@sean-clayton quick update: @sgress454 just stumbled upon this: nodejs/node#14132 Looks like the inconsistency is indeed related to the cache busting in include-all (it's there to allow for live reloading backend code). I'll let Scott go into the details as-needed, but the short answer is that, in node 8.3, the behavior for "children" in the require cache changed. We're kicking around some ways we could make Sails not rely on this, because obviously we don't want to be dependent on a feature of Node.js that might very well change again without a major version bump... |
@sean-clayton re: global sails -- Sails isn't globalized at the time that services are loaded, but again, if you just do your work inside of |
Hi guys, I get the error during the application lift when requiring some files which are required inside my hooks init function:
Where XXX config is defined in the file Thanks for your work! UPDATE: I forgot to mention that the same code run with |
@mattbrun thanks for the report! |
require('sails').config
Sails version: 1.0.0-36
Node version: 8.3.0
NPM version: 5.3.0
Operating system: Debian GNU/Linux 8.7 (jessie)
Our project uses Sails 1.0.0-33, it boots perfectly on Node 8.2.0, but it breaks on Node 8.3.0. The error is:
Match against undefined or null is just when we try to deconstruct Sails to get a configuration value in a service file.
My code looks like this:
I tried removing
let sails = require('sails')
but it then it says thatsails is undefined
🤔 however, it should be globally available, right?Node 8.2.0 works perfectly though.
Also: Doing
require('sails')
and then usingsails.<property>
from a function and not at load time works.Edit: I had 1.0.0-33 at the beginning, then upraded to 1.0.0-36 and I get the same.
The text was updated successfully, but these errors were encountered: