Sails.js datastore fails after some time - sails.js

I have configured my dummy Sails.js application to work with mysql database like so:
module.exports.datastores = {
default: {
adapter: require('sails-mysql'),
url: 'mysql://mysql:mysql#localhost:3306/sails',
}
};
and it works fine, both read and write operations work great. However, after some time http requests begin to fail with 500 code and the error is:
AdapterError: Unexpected error from database adapter: Could not run
select() because of 2 problems:
• "datastore" is required, but it was not defined.
• "models" is required, but it was not defined.
While this is happening, I keep getting this error with every page refresh. If I kill the server and lift it again, the database works fine for some time. I couldn't find much on this error online. Not sure where to look for the solution.
Below is my package.json just in case
{
"name": "ration",
"private": true,
"version": "0.0.0",
"description": "a Sails application",
"keywords": [],
"dependencies": {
"#sailshq/connect-redis": "^3.2.1",
"#sailshq/lodash": "^3.10.3",
"#sailshq/socket.io-redis": "^5.2.0",
"sails": "^1.5.0",
"sails-hook-apianalytics": "^2.0.3",
"sails-hook-autoreload": "^1.1.0",
"sails-hook-organics": "^2.0.0",
"sails-hook-orm": "^4.0.0",
"sails-hook-sockets": "^2.0.0",
"sails-mysql": "2.0.0"
},
"devDependencies": {
"eslint": "5.16.0",
"grunt": "1.0.4",
"htmlhint": "0.11.0",
"lesshint": "6.3.6",
"sails-hook-grunt": "^5.0.0"
},
"scripts": {...},
"main": "app.js",
"repository": {
"type": "git",
"url": "git://github.com/anonymous node/sails user/ration.git"
},
"author": "anonymous node/sails user",
"license": "",
"engines": {
"node": "^16.13"
}
}

Turned out this problem was caused sails-hook-autoreload and I'm a bit ashamed I did not notice the pattern that causes this error every time the hook was triggered. I ended up using nodemon for automated server restarts and everything works fine. Hope this will help somebody out there.

Related

Sanity Deployment on Vercel Issue: Cannot find module 'sanity' even though package is installed

So i'm trying to deploy sanity/nextjs on vercel. It runs fine locally but for the production build I keep getting the same error.
Here's the main error:
> build
> next build
info - Linting and checking validity of types...
Failed to compile.
./sanity/sanity.config.ts:1:28
Type error: Cannot find module 'sanity' or its corresponding type declarations.
> 1 | import {defineConfig} from 'sanity'
| ^
2 | import {deskTool} from 'sanity/desk'
3 | import {visionTool} from '#sanity/vision'
4 | import {schemaTypes} from './schemas'
Error: Command "npm run build" exited with 1
My sanity package.json:
{
"name": "nft-drop",
"private": true,
"version": "1.0.0",
"main": "package.json",
"license": "UNLICENSED",
"scripts": {
"dev": "sanity dev",
"start": "sanity start",
"build": "sanity build",
"deploy": "sanity deploy",
"deploy-graphql": "sanity graphql deploy"
},
"keywords": [
"sanity"
],
"dependencies": {
"#sanity/vision": "^3.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-is": "^18.2.0",
"sanity": "^3.0.0",
"styled-components": "^5.2.0"
},
"devDependencies": {
"#sanity/cli": "^3.2.3",
"#sanity/eslint-config-studio": "^2.0.1",
"eslint": "^8.6.0",
"prettier": "^2.8.3",
"typescript": "^4.0.0"
},
"prettier": {
"semi": false,
"printWidth": 100,
"bracketSpacing": false,
"singleQuote": true
}
}
My main folder package.json:
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"#next/font": "^13.1.2",
"#sanity/image-url": "^1.0.1",
"#thirdweb-dev/react": "^3.6.9",
"#thirdweb-dev/sdk": "^3.6.9",
"ethers": "^5.7.2",
"next": "latest",
"next-sanity": "^4.0.6",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"#sanity/cli": "^3.2.3",
"#types/node": "18.11.3",
"#types/react": "18.0.21",
"#types/react-dom": "18.0.6",
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"tailwindcss": "^3.2.4",
"typescript": "4.9.4"
}
}
Thanks for your help.
I've checked that I have the 'sanity' package installed. I've added the recommended 'vercel.json' file and I also have the #sanity/cli installed. I've checked my local env setup to make sure that was also on vercel.
Maybe i've overinstalled the sanity packages in trying to solve it?
This is my first time using sanity, nextjs, and vercel so I've run out of ideas and haven't found the same issue answered elsewhere yet.
I had this issue as well, and it seems to be related to Sanity v3 which only came out a month ago - I rolled back to sanity v2 and it fixed the deployment issue
You can try to add .vercelignore in the root file and add sanity in there to ignore the whole folder
The fix is to move your sanity client config file (aka wherever you have your .env variables setup - in my case: sanity.ts) into a lib folder in the root directory. If the file itself is in the root directory, it will not build.
Updating the import statement from
import {defineConfig} from 'sanity'
to
import {defineConfig} from 'sanity/lib/exports'
worked for me.

Error: Jest: Got error running globalSetup ../#shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error

I'm following the documentation on jestjs.io. When I try to run a test I get this error:
Error: Jest: Got error running globalSetup - /home/.../node_modules/#shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error!
This happened both when I've used typescript and also when I created a simple app using javascript instead:
package.json:
{
"name": "mongojest",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"#shelf/jest-mongodb": "^3.0.1"
},
"scripts": {
"test": "jest"
},
"dependencies": {
"jest": "^28.1.0"
}
}
jest.config.js:
module.exports = {
coverageProvider: "v8",
"preset": "#shelf/jest-mongodb"
};
I haven't made any changes other than the minimum installs to get it running.
I got around this issue by installing Ubuntu 20.04. I was using the newer Ubuntu 22.04 and it seem to have caused some issues.
I installed typescript in my project. That was enough to run. Follow my configuration files
//package.json
{
"name": "research-with-programmers-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --passWithNoTests --silent --noStackTrace --runInBand",
"test:verbose": "jest --passWithNoTests --runInBand",
"test:unit": "yarn test -- --watch -c jest-unit-config.ts",
"test:integration": "yarn test -- --watch -c jest-integration-config.ts",
"test:staged": "yarn test -- --findRelatedTest",
"test:ci": "yarn test -- --coverage"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"#shelf/jest-mongodb": "^4.1.0",
"#types/bcrypt": "^5.0.0",
"#types/jest": "^28.1.8",
"#types/mongodb": "^4.0.7",
"#types/node": "^18.7.13",
"#types/validator": "^13.7.6",
"#typescript-eslint/eslint-plugin": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-standard-with-typescript": "^22.0.0",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"git-commit-msg-linter": "^4.1.3",
"husky": "^8.0.1",
"jest": "^29.0.1",
"lint-staged": "^13.0.3",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^4.8.2"
},
"dependencies": {
"bcrypt": "^5.0.1",
"mongodb": "^4.10.0",
"validator": "^13.7.0"
}
}
//jest-config.ts
export default {
roots: ['<rootDir>/src'],
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
'!<rootDir>/src/**/protocols/*.ts',
'!<rootDir>/src/**/*protocols.ts',
'!<rootDir>/src/**/models/*.ts',
'!<rootDir>/src/**/usecases/*.ts',
'!<rootDir>/src/**/index.ts'
],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageProvider: 'v8',
testEnvironment: 'node',
preset: '#shelf/jest-mongodb',
transform: {
'.+\\.ts$': 'ts-jest'
}
}
// jest-mongodb-config.ts
export default {
mongodbMemoryServerOptions: {
instance: {
dbName: 'jest'
},
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false
}
}

facing error TS2339: Property 'then' does not exist on type 'StepDefinitions & Hooks'

facing error TS2339: Property 'then' does not exist on type 'StepDefinitions & Hooks'.
when I am trying to run tsc -w
tried all the solution which I know but nothing is working out.
Feature file:
Feature: Login creation for Amazon AWS
Scenario: Successful creation of Login
Given User navigate to Home Page
When User enter email and other details
Then Login is created sucessfully
Package.json
{
"name": "package.json",
"version": "1.0.0",
"description": "package",
"main": "index.js",
"dependencies": {
"#types/node": "^12.7.5"
},
"scripts": {
"test": "./node_modules/.bin/cucumber-js -p default"
},
"compilerOptions": {
"target": "es6"
},
"devDependencies": {
"#types/chai": "^4.2.2",
"#types/cucumber": "^4.0.7",
"chai": "^4.2.0",
"cucumber": "^5.1.0",
"cucumber-pretty": "^1.5.2",
"cucumber-tsflow": "^3.2.0",
"exceljs": "^2.0.1",
"protractor": "^5.4.2",
"protractor-cucumber-framework": "^6.1.3",
"ts-node": "^8.3.0",
"typescript": "^3.6.3",
"xlsx": "^0.15.1"
},
"author": "Bharani",
"license": "ISC"
}
Step Definition file:
import { Given, When, Then } from "cucumber"
Given("User navigate to Home Page", function(){
console.log("hafd");
});
When("User enter email and other details",function(){
console.log("dfhagsdf");
});
Then("Login is created sucessfully",function(){
console.log("dhfhd");
});
Package.json:
{
"name": "package.json",
"version": "1.0.0",
"description": "package",
"main": "index.js",
"dependencies": {
"#types/node": "^12.7.5"
},
"scripts": {
"test": "./node_modules/.bin/cucumber-js -p default"
},
"compilerOptions": {
"target": "es6"
},
"devDependencies": {
"#types/chai": "^4.2.2",
"#types/cucumber": "^4.0.7",
"chai": "^4.2.0",
"cucumber": "^5.1.0",
"cucumber-pretty": "^1.5.2",
"cucumber-tsflow": "^3.2.0",
"exceljs": "^2.0.1",
"protractor": "^5.4.2",
"protractor-cucumber-framework": "^6.1.3",
"ts-node": "^8.3.0",
"typescript": "^3.6.3",
"xlsx": "^0.15.1"
},
"author": "Bharani",
"license": "ISC"
}
Error in console:
'''[16:44:58] Starting compilation in watch mode...
POM_TS_CUCUMBER/Featurefile/stepdefinition/Steps.ts:3:32 - error
TS2339: Property 'then' does not exist on type 'StepDefinitions &
Hooks'.
3 defineSupportCode(({Given,When,then}) =>{
~~~~
[16:45:04] Found 1 error. Watching for file changes. '''
You have written Then in feature file which is not from the cucumber library. Try writing then statement again from cucumber library and try again.

Heroku push rejected failed: npm ERR! 404 Not Found: event-stream#3.3.6. This causes a build fail

I am getting the error:
Heroku push rejected failed to define node.js node not defined in package.json
My app works locally, this is an Express MongoDB using handlebars. My gitignore has node_modules in it and the strange part is I am using nodemon and not node.
package.json:
{
"name": "Jukebox",
"version": "1.1.0",
"engines": {
"node": "11.3.0",
"npm": "6.4.1"
},
"private": true,
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
"dependencies": {
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^6.1.0",
"express": "~4.16.0",
"hbs": "~4.0.1",
"http-errors": "~1.6.2",
"method-override": "^3.0.0",
"mongoose": "^5.3.6",
"morgan": "~1.9.0",
"nodemon": "^1.18.4"
},
"description": "Jukebox is an app where users can add their favorite songs for others to discover. There will be a maximum number of 32 songs that can be added. When user selects genre the artists of that genre will populate the grid and a button will appear to add artist.",
"main": "app.js",
"repository": {
"type": "git",
"url": "git+https://github.com/chuckderosier/Jukebox.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/chuckderosier/Jukebox/issues"
},
"homepage": "https://github.com/chuckderosier/Jukebox#readme"
}
You need to specify a Node.js version within your package.json that matches
the runtime you’re developing and testing with.
Do the following:
Within your cmd line type: node --version and see what version of Node you're developing with.
Add an engines section within your package.json specifying your node version from step 1. For example something similar to this:
"engines": {
"node": "10.3.0"
}
For more information checkout the Heroku documentation for Nodejs buildpacks

Getting "connect ECONNREFUSED" error when I "npm run seed" in feathers api with mongodb

I'm learning react and feathers. For my recipes app that I've made in react I use feathers api and mongodb. I have some seeds as examples in /src/seeds.js and just began to set up everything in feathers but when I want to run my seeds(npm run seed) and check if it works on feathers localhost:3030/recipes I got this error:
Error creating user! { Error: connect ECONNREFUSED 127.0.0.1:3030
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3030,
response: undefined }
I don't know the error is because of connection or creating user!
I checked my mondo db, it runs.
this is package.json, just in case:
{
"name": "recipes-api(par)",
"description": "api for recipes app",
"version": "0.0.0",
"homepage": "",
"main": "src/",
"keywords": [
"feathers"
],
"license": "MIT",
"repository": {},
"author": {},
"contributors": [],
"bugs": {},
"engines": {
"node": ">= 0.12.0"
},
"scripts": {
"test": "npm run jshint && npm run mocha",
"jshint": "jshint src/. test/. --config",
"start": "node src/",
"mocha": "mocha test/ --recursive",
"seed": "node src/seeds.js"
},
"dependencies": {
"body-parser": "^1.17.1",
"compression": "^1.6.2",
"cors": "^2.8.3",
"feathers": "^2.1.1",
"feathers-authentication": "^0.7.12",
"feathers-client": "^2.2.0",
"feathers-configuration": "^0.3.3",
"feathers-errors": "^2.6.3",
"feathers-hooks": "^1.8.1",
"feathers-mongoose": "^3.6.2",
"feathers-rest": "^1.7.2",
"feathers-socketio": "^1.6.0",
"mongoose": "^4.9.6",
"passport": "^0.3.2",
"serve-favicon": "^2.4.2",
"superagent": "^3.5.2",
"winston": "^2.3.1"
},
"devDependencies": {
"jshint": "^2.9.4",
"mocha": "^3.3.0",
"request": "^2.81.0"
}
}
Before adding seeds I should have seen {"total":0,"limit":5,"skip":0,"data":[]} in http://localhost:3030/recipes that I'm still having it but after running seeds I should see the list of my recipes.
Anythings else that I need to copy here from my code? any idea?