I just decided to upgrade an existing Sails project to 1.0.0 and managed to get through most of the upgrade process until I tried connecting to the database. When attempting to lift this is the error I receive:
The adapter used by the default datastore is not compatible with
the current version of Sails/Waterline.
The adapter should expose a valid adapterApiVersion.
If you're using the beta release of Sails 1.0, try:
npm install --save sails-disk#beta
My datastores.js file contains the following:
module.exports.datastores = {
// In previous versions, datastores (then called 'connections') would only be loaded
// if a model was actually using them. Starting with Sails 1.0, _all_ configured
// datastores will be loaded, regardless of use. So we'll only include datastores in
// this file that were actually being used. Your original `connections` config is
// still available as `config/connections-old.js.txt`.
'developmentPostgres': {
adapter: require('sails-postgresql'),
url: process.env.postgresHost,
user: process.env.postgresUser,
password: process.env.postgresPassword,
database: process.env.postgresDatabase
}
};
Where all of the values are provided as environment variables. "sails-postgresql": "^1.0.0" is installed and saved in package.json
models.js also contains the following line: datastore: 'developmentPostgres', which to my understanding means that all of my models should be using the above database by default.
Up until this point the upgrade process has been very straightforward. I assume I am just missing something simple here as well. I would appreciate any insight anyone can provide and would be happy to provide any additional information as well.
Turns out the project looks for a datastore labeled default. Changing the name to default in both datastore.js and model.js solved the issue.
Related
I'm building a NextJs application which uses a set of abstractions to enable code from both react (Component logic etc.) and node (API logic) to utilize same types and classes. The motive here is to make the development process seem seamless across client side and server side.
For example. a call on User.create method of the User class will behave differently based on the runtime environment (ie. browser or node) - on the browser, it will call an api with a POST request and on server it will persist data to a database.
So far this pattern worked just fine, and I like how it all turned out in terms of the code structure. However, for this to work, I have to import modules responsible for working on the server and browser to a single module (which in this case is the User class) this leads to a critical error when trying to resolve dependencies in each module.
For example I'm using firebase-admin in the server to persist data to the Firebase Firestore. But it uses fs which cannot be resolved when the same code runs on the browser.
As a work around I set the resolve alias of firebase-admin to false inside the webpack configuration (given it runs on browser) see code below.
/** next.config.js **/
webpack: (config, { isServer }) => {
if (!isServer) {
// set alias of node specific modules to false
// eg: service dependencies
config.resolve.alias = {
...config.resolve.alias,
'firebase-admin': false,
}
} else {
// set alias of browser only modules to false.
config.resolve.alias = {
...config.resolve.alias,
}
}
While this does the trick, it won't be much long until the process gets really tedious to include all such dependencies within resolve aliases.
So, my approach to this is to write a script that runs prior to npm run dev (or manually) that will read all dependencies in package.json and SOMEHOW identify packages that will not run on a specific runtime environment and add them to the webpack config. In order to this, there should be a way to identify this nature of each dependency which I don't think is something that comes right out of the box from npm or the package itself.
Any suggestion on how this can be achieved is really appreciated. Thanks`
I have a backend application (Node.JS) that uses mssql (v7) and sequelize (v6) npm packages.
Since my production DB configuration is (and can be only) accessed by an AGL, hence I need to set multisubnetfailover=true in the DB connection string.
Although support for this existed in previous versions, I am unable to find the same in the current stable versions of the respective packages. (Here's a sample code for previous sequelize and mssql version)
Is there a way to enable this in the newer version?
For sequelize (v6):
Solution:
...existing sequelize configuration
dialect: "mssql",
dialectOptions : {
options: {
multiSubnetFailover: true,
}
}
...
Approach:
I was looking at the source code links sent by #AlwaysLearning in the comments above, and found that, if multiSubnetFailover's value is not a boolean, an error is thrown.
I then updated my configuration to dialectOptions.multiSubnetFailover : "1234", however I did not get the TypeError I was expecting. Then I looked at some more code and found that multiSubnetFailover should be used inside dialectOptions.options.
For mssql (v7):
Got help from a contributor.
...existing mssql configuration
options: {
multiSubnetFailover: true,
}
...
Cheers!
I've been using NuxtJS (v2.15.8) with Nuxt Firebase (v7.6.1), running on NodeJS engine 12 (v12.21.0 to be exact) for the web application I've been developping incrementally for the past couple of years and my web app is now quite complex.
I am trying to upgrade NodeJS to the latest LTS version (v16.13.2) and encounter one major issue after switching version of NodeJS (using nvm) and changing the package.json of my five packages from node 12 to node 16 :
package.json :
"engines": {
"node": "16",
..
},
When running exactly the wame web application after these changes, it starts correctly but Firebase Rules seem to break, with this error FirebaseError: false for 'get' # L61, false for 'get' # L268.
It is a cryptic error, but from experience and from all I could find online, it happens when a call to Firestore that gets blocked by defined Firebase Security rules). In my case, it happens on a "onSnapshot" call to listen to the changes of the currently logged in user. Some other calls to Firestore (using "get" and not "onSnapshot") seem to work fine, and the Firebase Authentication works well too.
Here is the full error stack :
loggedInUser.js?384a:65 Error listening to user changes
FirebaseError: false for 'get' # L61, false for 'get' # L268
at new n (prebuilt-306f43d8-45d6f0b9.js?23bd:188:1)
at eval (prebuilt-306f43d8-45d6f0b9.js?23bd:10426:1)
at eval (prebuilt-306f43d8-45d6f0b9.js?23bd:10427:1)
at n.onMessage (prebuilt-306f43d8-45d6f0b9.js?23bd:10449:1)
at eval (prebuilt-306f43d8-45d6f0b9.js?23bd:10366:1)
at eval (prebuilt-306f43d8-45d6f0b9.js?23bd:10397:1)
at eval (prebuilt-306f43d8-45d6f0b9.js?23bd:15160:1)
at eval (prebuilt-306f43d8-45d6f0b9.js?23bd:15218:1)
The portion of code triggerring the error is :
listenUser({ commit }, userId) {
const userRef = this.$fire.firestore.collection('users').doc(userId);
userListener = userRef.onSnapshot(function(userDoc) {
if (userDoc.exists) {
const user = userConverter.fromFirestoreData(userDoc.data());
commit('SET_LOGGED_IN_USER', user);
}
},
function(error) {
console.error("Error listening to user changes", error);
});
},
As soon as I revert back to Node 12, the same call works fine and isn't blocked by the Firebase rules, so the error doesn't appear.
I therefore have several questions :
Does anyone understand what's happening there ? Is there known changes in the behavior of Firebase rules directly related to the NodeJS engine ?
Do you think this issue can come from Nuxt or its Nuxt Firebase module are not working correctly under NodeJS 16 ?
It is required to also upgrade NuxtJS to a newer version or should it be possible to simply update the Node Engine ?
Is it required to update to a newer version of Firebase (modular implementation) despite the Nuxt Firebase module stating :
"This module does not support the new modular syntax from Firebase v9+. If you plan to use the new modular mode of Version 9, we advise you to implement Firebase manually as described in the following medium article. It is currently unclear when, and if, this module will support the new modular mode."
Source : their Github repo
Any help to understand what's going on here is welcome !!
Thanks a lot for your help !
Regarding your questions:
I'm unaware of what is causing this issue but there are no known changes in the behavior of Firebase Rules depending on the NodeJS version you are using.
It's hard to assess without having more information. However I deployed a sample NuxtJS app following this guide on NodeJS 16 and it worked. Additionally the error code, as you mentioned, is caused when a Firestore Rule blocks a query. Therefore I think the root cause might be in the NuxtJS firebase module.
I wasn't able to find any documentation suggesting that you need to upgrade NuxtJS when upgrading NodeJS. Additionally you mentioned that you are using version 2.15.8 of NuxtJS which according to this release notes is the latest version.
I'm unsure on further support for NuxtJS considering that statement, but according to this Firebase documentation it is recommended to upgrade to version 9.
If you decide to attempt to upgrade to firebase v9 make sure to also upgrade Nuxt Firebase module to version 8.0.0 or higher, this version provides support to the compat library so you can use Firebase v9 although still with the old syntax, more information can be found here.
Lastly, if you'd like to test if a Firebase rule is working as expected you can quickly test it using the Rules Playground.
Long story short : upgrading to Firebase v9 worked.
Before I did that, I got stuck with rules preventing me to access firestore documents as soon as I tried running the project under Node16 engine.
So I had to do the following changes :
updating Firebase to v9
implement the configuration through a plugin rather than the nuxt-firebase module
make all the required changes in my code to make use of v9 modular (I didn't try using the compat version)
Now that I use the latest version of Firebase, I tried again switching to NodeJS 16 and it runs fine, including the Firebase security rules.
I got an interview assessment next week and they provided me a sample code project of what to expect. The problem is I'm having a LOT of trouble simply setting it up to run as expected...
Edited: Removed project for privacy
I cloned the project and installed all dependencies.
Problem 1
I followed the README in which I created a Database called messenger and then created a .env file in the server directory. The problem is I can't retrieve any values from that .env file through process.env.REACT_APP_CUSTOM_VAR. Console.logging "process.env" does not show ANY custom variables. It's as if they weren't even created...
Problem 2
On the frontend side, it should have been simple (npm install and then npm start). When starting, I found that there was NO CSS applied (despite reading the code and there's Material UI used). When I inspected the page, I'm getting the error 'The server responded with a status of 431 (Request header fields too large).
I have a hard time believing the company gave me super broken code to the point where I can't even run the sample code properly... Can anyone please help me and try installing the code project above? Please let me know if you got the same problem or found any solutions!
Submit an issue requesting that they add .nvmrc and package-lock.json such that you can ensure your machine is prepared to absorb dependencies and properly posture with the correct version of node. It's a crap-shoot of testing various versions of node against their build otherwise.
Your best bet is to check the first publish date of the client (javascript) code against the latest versions of node from that time. It sucks, but that's what I would do.
The project runs fine.
Theres not really styling applied, but that seems to be intentional.
Most likely you would benefit from using whatever database you have access to that already works (in my case, mssql) by changing the db.js
const db = new Sequelize('dbname', 'user', 'password', {
host: 'host',
port: 1433,
logging: false,
dialect: 'mssql',
dialectOptions: {
encrypt: true,
},
});
What you should however not do if you want the job, is critique it. It works just fine as the baseline for a recruitment assignment. Your enviroment is the issue in this case.
Do not forget to run the seed on the backend.
For the problem 1 on the server, I've create an .env file on the ./server directory and logging process.env logged the variables from that file. Also, on the backend, you don't need the REACT_APP_CUSTOM_VAR prefix when accessing environment variables.
For the problem 2 on the frontend, after the instalation, the client loaded the css from mui properly. I'm using node 14.17.0.
I'm encountering this weird message out of blue on my Node server (Express + GraphQL) in the terminal window. Message doesn't say where it comes from.
Anyone experiencing this problem or any idea why it's happening?
Github Issue in Typegoose Repository
Typegoose is changing how it handles enum properties, and the old behaviour is deprecated.
Check for breaking changes
If you are working on an existing project, then review the documentation to ensure your app and DB will be compatible with the new behaviour:
Enum properties
useNewEnum flag
Opt-in to the new enum behaviour
Run the following as early as possible in your start-up code:
import { setGlobalOptions } from "#typegoose/typegoose";
setGlobalOptions({
globalOptions: {
useNewEnum: true,
},
});
If you still get the warnings, then try the following:
Ensure the code is running before any other app start-up logic
Run the code before any other imports