json-server --watch db.json in error TypeError: lodash.runInContext is not a function - json-server

C:\Documents\Project>json-server --watch db.json
{^_^}/ hi!
Loading db.json
TypeError: lodash.runInContext is not a function
at module.exports (C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\node_modules\lowdb\lib\main.js:12:18)
at C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\lib\cli\utils\load.js:45:15
at new Promise ()
at module.exports (C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\lib\cli\utils\load.js:36:10)
at start (C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\lib\cli\run.js:112:12)
at module.exports (C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\lib\cli\run.js:149:3)
at module.exports (C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\lib\cli\index.js:86:3)
at Object. (C:\Users\Taras Kundyk\AppData\Roaming\npm\node_modules\json-server\lib\cli\bin.js:6:14)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
I can't run the server.
I've already tried to install (and reinstall) json-server global and locally npm install -g json-server and npm install json-server and then run json-server --watch db.json, but it doesn't work.

That's an issue with lodash#4.17.16.
It was solved in newer versions, so you can update using npm install lodash#^4.17.19

Related

TypeError: JwtStrategy requires a secret or key

I've read the million threads with the same issue but I couldn't solve it :(
This is an old project I made and I need to access to it again but I'm getting the following error when running npm start:
> express-typescript-starter#0.1.0 start
> npm run tsc && npm run serve
> express-typescript-starter#0.1.0 tsc
> tsc
> express-typescript-starter#0.1.0 serve
> ts-node src/server.ts
{"level":"debug","message":"Logging initialized at debug level"}
C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\passport-jwt\lib\strategy.js:45
throw new TypeError('JwtStrategy requires a secret or key');
^
TypeError: JwtStrategy requires a secret or key
at new JwtStrategy (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\passport-jwt\lib\strategy.js:45:15)
at Object.<anonymous> (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\src\config\passport.ts:6:28)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module.m._compile (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:858:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:861:12)
at Module.load (node:internal/modules/cjs/loader:1027:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Module.require (node:internal/modules/cjs/loader:1051:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\src\app.ts:16:1)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module.m._compile (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:858:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Object.require.extensions.<computed> [as .ts] (C:\Users\alan_\Desktop\cdng\mern-finance-server-master\node_modules\ts-node\src\index.ts:861:12)
at Module.load (node:internal/modules/cjs/loader:1027:32)
This is src/config/passport.ts:
import passport from 'passport'
import { Strategy as JwtStrategy, ExtractJwt } from 'passport-jwt'
import userServices from '../services/userServices'
import { JWT_SECRET } from '../util/secret'
export const jwtStrategy = new JwtStrategy(
{
secretOrKey: JWT_SECRET,
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
},
async (payload: any, done: any) => {
const userEmail = payload.email
const foundUser = await userServices.findUserByEmail(userEmail)
done(null, foundUser)
}
)
When running "npm i" I'm getting a bunch of errors as well but I could --force it:
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: jest-config#27.5.1
npm WARN Found: ts-node#8.10.2
npm WARN node_modules/ts-node
npm WARN dev ts-node#"^8.6.2" from the root project
npm WARN
npm WARN Could not resolve dependency:
npm WARN peerOptional ts-node#">=9.0.0" from jest-config#27.5.1
npm WARN node_modules/jest-config
npm WARN jest-config#"^27.5.1" from #jest/core#27.5.1
npm WARN node_modules/#jest/core
npm WARN 1 more (jest-cli)
npm WARN
npm WARN Conflicting peer dependency: ts-node#10.9.1
npm WARN node_modules/ts-node
npm WARN peerOptional ts-node#">=9.0.0" from jest-config#27.5.1
npm WARN node_modules/jest-config
npm WARN jest-config#"^27.5.1" from #jest/core#27.5.1
npm WARN node_modules/#jest/core
npm WARN 1 more (jest-cli)
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: ts-jest#26.5.6
npm ERR! Found: jest#27.5.1
npm ERR! node_modules/jest
npm ERR! dev jest#"^27.5.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jest#">=26 <27" from ts-jest#26.5.6
npm ERR! node_modules/ts-jest
npm ERR! dev ts-jest#"^26.5.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: jest#26.6.3
npm ERR! node_modules/jest
npm ERR! peer jest#">=26 <27" from ts-jest#26.5.6
npm ERR! node_modules/ts-jest
npm ERR! dev ts-jest#"^26.5.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
You can see the whole repo here.
Thanks!
I'm not going to attempt to fix your conflicts, but npm i -force will allow everything to be installed.
You will also need to place a .env file in the root and ensure it has a JWT_SECRET secret value.
There are also a lot of other .env values required. Your .env should look like this (or production):
JWT_SECRET = 'jhagdhjwf'
MONGODB_URI = 'mongodb://localhost:27017/local'
PORT = 3000
CLOUD_NAME = 'Your cloud name'
CLOUDINARY_API_KEY = '123123123123'
CLOUDINARY_API_SECRET = 'abc123abc123abc123abc123'
NODE_ENV = 'production'
I don't know why you didn't think an .env was not required. I thought you said this was your project?
As you will also know, you have to have cloudinary API config and also a running mongodb server, on which you store your data.
Eg, install docker and run the command to get a quick running local version:
docker run -d -p 27017:27017 --name test-mongo mongo:latest
I did a pull of the code and everything works locally. Add this .env and it will work:
> express-typescript-starter#0.1.0 start
> npm run tsc && npm run serve
> express-typescript-starter#0.1.0 tsc
> tsc
> express-typescript-starter#0.1.0 serve
> ts-node src/server.ts
{"level":"debug","message":"Logging initialized at debug level"}
(node:78699) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
App running on port 3000
Opening http://localhost:3000/api/v1/users will give you the expected [] response. I assume you have a front end somewhere.
Everything should be working as expected.
Extra: Your import { JWT_SECRET } from '../util/secret' is not the right file name. In your repo it is https://github.com/AlanFPS/mern-finance-server/blob/master/src/util/seccret.ts. Your import is looking for secret but your file is called seccret (two c's).

can't create and generate typeorm migration

i want to do generate for entity which i have created to database using typeorm
but i get an error like this
Generates a new migration file with sql needs to be executed to update schema
Not enough non-option arguments: got 0, need at least 1
Note: This command was run via npm module 'win-node-env'
npm ERR! code ELIFECYCLE
npm ERR! crud_api_reuse#0.0.1 typeorm: NODE_ENV=migration ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -f --config ./src/config/ormconfig.ts "migration:generate" "--name" "create_table_user"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the crud_api_reuse#0.0.1 typeorm script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\jojo\AppData\Roaming\npm-cache\logs\2022-11-13T12_28_28_622Z-debug.log
this is my project structure
inside my ormconfig.ts file like this
`
import * as dotenv from 'dotenv';
import { TypeOrmModuleOptions } from '#nestjs/typeorm';
dotenv.config();
const dir = process.env.NODE_ENV == 'migration' ? 'src' : 'dist';
export default <TypeOrmModuleOptions>{
type: process.env.DATABASE_CONNECTION,
host: process.env.DATABASE_HOST,
port: Number(process.env.DATABASE_PORT),
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE_NAME,
entities: [`${dir}/**/*.entity.{js,ts}`],
migrations: [`${dir}/models/migrations/*.{js,ts}`],
seeds: [`${dir}/models/migrations/seeds/*.seed.{js,ts}`],
factories: [`${dir}/models/migrations/seeds/factories/*.factory.{js,ts}`],
cli: {
migrationsDir: `${dir}/models/migrations`,
entitiesDir: `${dir}/models/entities`,
seedersDir: `${dir}/models/migrations/seeds`,
factoriesDir: `${dir}/models/migrations/seeds/factories`,
},
synchronize: false,
migrationsRun: false,
};
`
and the script that I created in the package.json file is like this
`
"typeorm": "NODE_ENV=migration ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -f --config ./src/config/ormconfig.ts",
"typeorm:migration:generate": "npm run typeorm migration:generate -- --name",
"typeorm:migration:create": "npm run typeorm migration:create -- --name",
"typeorm:migration:run": "npm run typeorm migration:run",
"typeorm:migration:revert": "npm run typeorm migration:revert",
"typeorm:seed": "NODE_ENV=migration ts-node ./node_modules/typeorm-seeding/dist/cli.js --configName ./src/config/ormconfig.ts",
"typeorm:seed:run": "npm run typeorm:seed seed",
"typeorm:schema:drop": "ts-node ./node_modules/typeorm/cli.js schema:drop"
`
but when I try to migrate, I get an error like the one above
so what should I do to be able to migrate?
I think the problem in your command to run migration missing some args.
Have you built before running new migration?
what is your typeorm version you're using?
in my case use 0.2.45:
my package.json script:
my command to create new migration base on entity (remember build first):
npm run migration:generate your_migration_name
try it!

Getting "Error: ENOENT: no such file or directory..." when trying to run amplify init

I'm trying to integrate AWS Amplify to my flutter project, on windows, VS code.
-I installed Amplify CLI via:
curl -sL https://aws-amplify.github.io/amplify-cli/install-win -o install.cmd && install.cmd
-I ran 'amplify configure' and created an IAM user.
-After creating a new flutter project, running 'amplify init' results in the error:
Error: ENOENT: no such file or directory, open 'C:\Users\Username\AppData\Roaming\SPB_Data\.aws\config'
at Object.openSync (fs.js:462:3)
at Object.openSync (pkg/prelude/bootstrap.js:739:32)
at Object.readFileSync (fs.js:364:35)
at Object.readFileSync (pkg/prelude/bootstrap.js:1025:36)
at Object.readFileSync (C:\snapshot\node_modules\aws-sdk\lib\util.js:95:26)
at IniLoader.parseFile (C:\snapshot\node_modules\aws-sdk\lib\shared-ini\ini-loader.js:6:47)
at IniLoader.loadFrom (C:\snapshot\node_modules\aws-sdk\lib\shared-ini\ini-loader.js:56:30)
at getRegion (C:\snapshot\node_modules\aws-sdk\lib\node_loader.js:116:32)
at Config.region (C:\snapshot\node_modules\aws-sdk\lib\node_loader.js:171:18)
at Config.set (C:\snapshot\node_modules\aws-sdk\lib\config.js:524:39)
at Config.<anonymous> (C:\snapshot\node_modules\aws-sdk\lib\config.js:359:12)
at Config.each (C:\snapshot\node_modules\aws-sdk\lib\util.js:512:32)
at new Config (C:\snapshot\node_modules\aws-sdk\lib\config.js:358:19)
at Object.loadServiceClass (C:\snapshot\node_modules\aws-sdk\lib\service.js:108:16)
at Object.Service [as constructor] (C:\snapshot\node_modules\aws-sdk\lib\service.js:47:29)
at new <anonymous> (C:\snapshot\node_modules\aws-sdk\lib\util.js:629:24)
at getConfiguredAmplifyClient (C:\snapshot\node_modules\amplify-provider-awscloudformation\lib\aws-utils\aws-amplify.js:42:14)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'C:\\Users\\Username\\AppData\\Roaming\\SPB_Data\\.aws\\config'
I lucked out in noticing that .aws folder was being generated in C:\Users\Username so I simply copied it to C:\Users\Username\AppData\Roaming\SPB_Data where it'd been missing.
The only problem now is when running additional Amplify configure commands, .aws is being updated only in C:\Users\Username , so I have to remember to copy-paste it to SPB_Data after every new profile is created.

How to make the kline node js command work?

I try to execute the node kline command, but it gives me an error:
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'C:\Program Files\nodejs\kline'
←[90m at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:725:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)←[39m
←[90m at internal/main/run_main_module.js:17:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
Although npm install kline was successful. Tell me, maybe I missed something.
From what I gathered the kline module doesn't seem to be designed for the command line. Besides this to install a package which should run from the command line, e.g. nodemon, you should add the -g flag to the npm install command. This will install your package in the global npm scope which also supports calling these packages as a command, if supported.

Sailsjs - sails lift command is not working on windows

I'm new to sailsjs. I created a new simple application with sailsjs and after run sails lift I got following error. Could you please anyone have an idea about this issue and tell how fix this.
Thanks.
info: Starting app...
C:\Users\kavi\AppData\Roaming\npm\node_modules\sails\errors\warn.js:48
'The local Sails dependency installed at `' + pathTo.localSails + '` ' +
^
ReferenceError: pathTo is not defined
at Object.module.exports.badLocalDependency (C:\Users\kavi\AppData\Roaming\n
pm\node_modules\sails\errors\warn.js:48:53)
at Sails.isLocalSailsValid (C:\Users\kavi\AppData\Roaming\npm\node_modules\s
ails\lib\app\private\isLocalSailsValid.js:51:14)
at Function.bound [as isLocalSailsValid] (C:\Users\kavi\AppData\Roaming\npm\
node_modules\sails\node_modules\lodash\dist\lodash.js:729:21)
at Command.module.exports (C:\Users\kavi\AppData\Roaming\npm\node_modules\sa
ils\bin\sails-lift.js:48:13)
at Command.<anonymous> (C:\Users\kavi\AppData\Roaming\npm\node_modules\sails
\node_modules\commander\index.js:249:8)
at Command.EventEmitter.emit (events.js:98:17)
at Command.parseArgs (C:\Users\kavi\AppData\Roaming\npm\node_modules\sails\n
ode_modules\commander\index.js:477:12)
at Command.parse (C:\Users\kavi\AppData\Roaming\npm\node_modules\sails\node_
modules\commander\index.js:370:21)
at Object.<anonymous> (C:\Users\kavi\AppData\Roaming\npm\node_modules\sails\
bin\sails.js:144:9)
at Module._compile (module.js:456:26)
Run npm install in your project root folder and after sails lift.
follow these steps,
1: npm install sails -g
2: npm install
note-run these commands as administrator