Sails Upgrade v10.5 Waterline "Migrate - safe" option gives errors? - node.js

When I upgraded Sails from V0.9 to V0.10 I ran into trouble with Waterline. I have exhausted my options as far as finding the solution online. The problem is:
Sails v0.10 ask for the migrate property to be set and I do set it inside my models.js config file - migrate:"safe".
My server console keeps giving me the following error:
node_modules/sails/node_modules/waterline/lib/waterline/core/validations.js:77
Object.keys(attrs[attr]).forEach(function(prop) {
TypeError: Object.keys called on non-object
Did anybody else run into this problem?

I realized after a bit that I had earlier added the following to my models. After removing it, I was able to run sails lift with no problems. Maybe check your models to ensure that everything is kosher.
autoCreatedAt: true,
autoUpdatedAt: true

Related

Unable to set up sample React project correctly?

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.

Debug compilation errors errors using Angular Universal in Angular 8 Application

A Brief Backstory
I have been implementing several upgrades to an Angular 8 application such as server-side rendering, and Google Analytics. As most developers do, I would code then test then move on to the next task. Typically I use ng serve to run the application as I am developing.
With Server-side rendering, to test speed, lazy-loaded images, etc, you need to use a node express server running on a generated JS file. After building, etc, I use Node prerender (my js file is prerender.js) to see what the application will look like prerendering on the server.
When I run this command, I should not get any errors, and I know my prender file will start a local server on port 4000.
The Problem
I get errors when running a node express server that I do not get when running with ng serve I recently got an error that said:
Unhandled Promise rejection: Cannot read property 'subscribe' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'subscribe' of undefined
at new ApplicationRef (C:\4towerdevelopment\dist-stage\server\main.js:45910:37)
at _createClass (C:\4towerdevelopment\dist-stage\server\main.js:37184:20)
at _createProviderInstance (C:\4towerdevelopment\dist-stage\server\main.js:37138:26)
at initNgModule (C:\4towerdevelopment\dist-stage\server\main.js:37044:32)
at new NgModuleRef_ (C:\4towerdevelopment\dist-stage\server\main.js:38176:9)
at Object.createNgModuleRef (C:\4towerdevelopment\dist-stage\server\main.js:38159:12)
at NgModuleFactory_.create (C:\4towerdevelopment\dist-stage\server\main.js:50821:25)
at C:\4towerdevelopment\dist-stage\prerender.js:29175:43
at ZoneDelegate.invoke (C:\4towerdevelopment\dist-stage\prerender.js:481:26)
at Object.onInvoke (C:\4towerdevelopment\dist-stage\prerender.js:28683:33) TypeError: Cannot read property 'subscribe' of undefined
at new ApplicationRef (C:\4towerdevelopment\dist-stage\server\main.js:45910:37)
at _createClass (C:\4towerdevelopment\dist-stage\server\main.js:37184:20)
at _createProviderInstance (C:\4towerdevelopment\dist-stage\server\main.js:37138:26)
at initNgModule (C:\4towerdevelopment\dist-stage\server\main.js:37044:32)
at new NgModuleRef_ (C:\4towerdevelopment\dist-stage\server\main.js:38176:9)
at Object.createNgModuleRef (C:\4towerdevelopment\dist-stage\server\main.js:38159:12)
at NgModuleFactory_.create (C:\4towerdevelopment\dist-stage\server\main.js:50821:25)
at C:\4towerdevelopment\dist-stage\prerender.js:29175:43
at ZoneDelegate.invoke (C:\4towerdevelopment\dist-stage\prerender.js:481:26)
at Object.onInvoke (C:\4towerdevelopment\dist-stage\prerender.js:28683:33)
The closest this gets me to figuring what actually is causing the problem is letting me know that a provider somewhere is causing this error. Looks like something should be an observable rather than a subscription. Beyond that, I guess I just start looking through my providers. My question is:
How can I force Angular to possibly throw this error when developing using ng serve?
If I can't, is there a better way to debug this current error besides combing through each provider? Or at least a way to tell what service is causing the issue?
Thank you.
UPDATE: Basic repo with problem here. I made a new angular project, made sure dependencies were up to date, installed ngUniversal per this post, and received this same Unhandled promise message when running node prerender
Verbatim I went to to the Angular cli website, made a new project (default Angular version installed was 8.3), installed Angular Universal, and tried to build. Same error message as above.
This looks like it was ApplicationRef that triggered the error, and that class is provided internally by the Angular core.
It could be failing in the constructor of the class, and there are a few calls to subscribe on Zone observables. I don't think you're going to find anything in your source code that directly relates to this error. It looks like a build configuration problem.
https://github.com/angular/angular/blob/bb52fb798c8578c461d21aee2b7623232184a5d3/packages/core/src/application_ref.ts#L562
I do not know what could possibly produce this problem, but I would start a new project with SSR and compare the differences to your current project.
Eventually, I dropped the angular 6 approach using pre-render, and went with the latest universal package. There seems to be no problem building using npm run build:ssr and serving dist/server.js in an express server. I am not sure what the problem was with the pre-render approach, but it seems to be outdated anyways. #Reactgular thanks for the feedback.

Getting './~/mongoose/lib/drivers/index.js' on ng build

I am using angular-cli for a MEAN stack application. It was working fine till yesterday, but today I am getting,
WARNING in ./~/mongoose/lib/drivers/index.js
8:11-74 Critical dependency: the request of a dependency is an expression
on ng build.
And if i still proceed and run the application i get,
Uncaught TypeError: __webpack_require__.i(...) is not a function
at Object.260 (main.bundle.js:913)
at __webpack_require__ (inline.bundle.js:53)
at Object.142 (main.bundle.js:11)
error on,
var User = __webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1_mongoose__["model"])("User", UserSchema);
in main bundle.
My ts file where this code is,
export const User: Model<IUser> = model<IUser>("User", UserSchema);
I searched on net and tried many things but had no luck.
Also some posts are suggesting to run web pack,but this was working till yesterday where I had no web pack.
I also hardcoded the mongoose's version value by removing caret from pacakge.json, had no luck again.
I made a different typescript class for entity model that is to be used on UI(angular 2) side.
Earlier was using the schema class as model in my UI too, hence was getting this error.

Relay/GraphQL Schema cache not updating when I update schema on server side

I have a React app using Relay and a remote GraphQL server. When I start the webpack server, I have it fetch the latest schema and feed it into the babel-relay-plugin.
It works great....except when I make a schema change. It appears React or Relay or webpack or something is caching the schema, because I'll get a Schema validation error in the browser console when I run the app. However, when I run the query manually against the GraphQL server using GraphIQL, the query is successful. So it would have to be some sort of cache on the react, relay, webpack side I'm thinking?
Things I've tried:
List item
Restarting webpack server
Removing node_modules and npm install
I've even tried restarting my computer (that actually seemed to work, but may be coincidence)
Thanks in advance for your help.
Turns out, of course, it was human error. I had cacheDirectory as true in my babel-loader query. You can read about it on the babel-loader readme (just do a find on page for 'cacheDirectory') https://github.com/babel/babel-loader
Once I changed that to false, which is the default. The problem went away. Hope that helps others.
This happened to me when I switched to Webpack 2.
The solution in my case was to move the babelRelayPlugin to be the first plugin to execute in .babelrc.
I'm not exactly sure on the why though.

ExpressJS, NodeJs, and MongoDB CRUD Skeleton - Mac

I have recently started working with MongoDB and had it working for a small web test with node JS However. I new my implementation wasn't following a decent MVC structure. I began searching and found this website and read through it. It's implementation look good as well as following a good MVS skeleton structure.
Express/NodeJS/MongoDB CRUD Skeleton
I got to the part where he says 'HOORAY! We've got a functioning web server that is talking to Mongo. Part 1 is accomplished." Unfortunately, I went the local host specified and it says the 'site cannot be reached'. I am still fairly new to NodeJs, Mongo and Express and cannot figure out why it is not working.
I am not sure if I have done a step wrong time and time again which I doubt or if there something is missing that is stopping me from having it working.
The part before it says:
Awesome. Now to test it's all working in the terminal type npm start and you shouldn't see any errors:
kcoleman-mbp:nodewebapp kcoleman$ npm start
> nodewebapp#0.0.1 start /Users/kcoleman/Documents/projects/nodewebapp
> node ./bin/www
That part I get the same outcome with:
nodewebApp and node./bin/www
The page says to navigate to 127.0.0.0:3000, but the localhost usualy defaults to 127.0.0.1. I didn't see any code in the page where he defines the port to 127.0.0.0.
So try connecting to 127.0.0.1:3000.
Coming to nodewebApp and node./bin/www, it could be because the command might be present in pacakge.json. If you delete the nodewebApp from package.json, you won't be seeing the same in the command.

Resources