onix-systems / nest-js-boilerplate Goto Github PK
View Code? Open in Web Editor NEWNest.js boilerplate
Home Page: https://onix-systems.com/
License: MIT License
Nest.js boilerplate
Home Page: https://onix-systems.com/
License: MIT License
failing to create a src file after finishing installing packages , tried it with nest v8 and v10 with nodejs v18 and v20
example of new interseptor:
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { getSerializeType } from '@decorators/serialization.decorator';
@Injectable()
export default class SerializeInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
return next.handle().pipe(
map((args) => {
const SerializeType = getSerializeType(context.getHandler());
const entity = new SerializeType();
if (Array.isArray(args)) {
if (args && args[0] && args[0].toJSON) {
return Object.assign(entity, { data: args.map((doc) => doc.toJSON()) });
}
return Object.assign(entity, { data: args });
}
if (args && args.toJSON) {
return Object.assign(entity, { data: args.toJSON() });
}
return Object.assign(entity, args);
}),
);
}
}
Lets start work with mongoose instance and change all repository
lean() -> exec()
Update nestjs to latest version (v9)
No sample command for running migration to seed roles table in database.
Issue: Bcrypt isn't installing with issues raised as GYP
Identified Problem: NPM isn't installing key libraries for Bcrypt
Resolution: Due to "Yo" using NPM, Bcrypt will not install and so the installation is failing as an issue with "Node-GYP". We've found by our own investigation that it is NPM causing the issues, as we switched the install from NPM install bcrypt to yarn add bcrypt and it fully installs without any issues.
Could you switch the generator to use Yarn?
The description says nestjs 8.XX but generating 7.XX project
During install generator stops with error below. Seems like a problem in wrong path, cause files was generated in /Users/denis/Projects/node/todojazz but in in dump I see path /Users/denis/Projects/node/package.json
node:events:368
throw er; // Unhandled 'error' event
^
AssertionError [ERR_ASSERTION]: Trying to copy from a source that does not exist: /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/generators/auth/templates/postgresql/oauth2/src/modules/
at EditionInterface.exports.copy (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/mem-fs-editor/lib/actions/copy.js:49:3)
at EditionInterface.module.exports [as copyTpl] (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/mem-fs-editor/lib/actions/copy-tpl.js:28:8)
at AuthenticationGenerator.module.exports (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/generators/auth/steps/writing.js:27:11)
at Object.<anonymous> (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/yeoman-generator/lib/index.js:991:25)
at /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/run-async/index.js:49:25
at new Promise (<anonymous>)
at /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/run-async/index.js:26:19
at runLoop.add.once.once (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/yeoman-generator/lib/index.js:992:11)
at Immediate._onImmediate (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/yo/node_modules/grouped-queue/lib/subqueue.js:48:34)
at processImmediate (node:internal/timers:464:21)
Emitted 'error' event on AuthenticationGenerator instance at:
at Immediate.<anonymous> (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/generator-nest-js-boilerplate/node_modules/yeoman-generator/lib/index.js:1022:20)
at processImmediate (node:internal/timers:464:21) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
❯ npm start
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /Users/denis/Projects/node/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/Users/denis/Projects/node/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/denis/.npm/_logs/2022-05-12T21_15_06_152Z-debug.log
/Users/denis/Projects/node/package.json
Seems like a problem with dependencies conflict:
npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected].
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/denis/.npm/_logs/2022-05-12T21_27_10_388Z-debug.log
return res.status(HttpStatus.BAD_REQUEST).json({
messages: ['string', 'string'],
error: 'string',
});
Grant permission from admin panel, directly to a user or a role.
Some files haven't been generated
Solution: Downgrade to Yo V4
During install I see the error:
394 verbose type range
395 verbose stack bson: No matching version found for bson@^4.6.2.
395 verbose stack at module.exports (/Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/npm-pick-manifest/index.js:209:23)
395 verbose stack at /Users/denis/.nvm/versions/node/v16.13.0/lib/node_modules/npm/node_modules/pacote/lib/registry.js:118:26
396 verbose cwd /Users/denis/Projects/node/todojazz
It's especially seems like a problem because I didn't install mongo driver
Dependency missing errors
Ubuntu: 20.04.3 LTS 64-bit
Node.js version: 16.13.2
NPM version: 8.1.2
Boilerplate configuration:
PM: npm,
Install stable packages?: yes
Application settings: default,
Auth: jwt,
Json Api: no
DataBase: MySQL,
Emails: no,
WebSockets: no,
Docker container: yes,
Heroku: no
Errors while installing:
npm ERR! > [email protected] prepublish
npm ERR! > yarn run build
......
npm ERR! sh: 1: yarn: not found
npm ERR! npm ERR! code 127
Errors after starting project:
Cannot find module '@nestjs/passport'
Cannot find module '@nestjs/jwt'
Cannot find module 'nestjs-redis'
Cannot find module 'ioredis'
// And after manually installing this packages appears new errors
Error: Cannot find module 'passport-local'
Error: Cannot find module 'passport-jwt'
After installing missing dependencies appears new error:
ERROR [ExceptionHandler] Nest can't resolve dependencies of the RedisCoreModule (Symbol(REDIS_MODULE_OPTIONS), ?). Please make sure that the argument ModuleRef at index [1] is available in the RedisCoreModule context.
It can be resolved by replacing nestjs-redis
module by @liaoliaots/nestjs-redis
package and modifying RedisModule code in app.module.ts
file:
// New code for RedisModule
RedisModule.forRoot({
config: {
url: process.env.REDIS_URL,
},
}),
After all of this work you will be able to successfully start application
src/modules/app/app.module.ts:2:31 - error TS2307: Cannot find module '@nestjs/typeorm' or its corresponding type declarations.
2 import { TypeOrmModule } from '@nestjs/typeorm';
~~~~~~~~~~~~~~~~~
src/modules/v1/users/schemas/user.entity.ts:6:8 - error TS2307: Cannot find module 'typeorm' or its corresponding type declarations.
6 } from 'typeorm';
~~~~~~~~~
src/modules/v1/users/users.module.ts:2:31 - error TS2307: Cannot find module '@nestjs/typeorm' or its corresponding type declarations.
2 import { TypeOrmModule } from '@nestjs/typeorm';
~~~~~~~~~~~~~~~~~
src/modules/v1/users/users.repository.ts:2:34 - error TS2307: Cannot find module '@nestjs/typeorm' or its corresponding type declarations.
2 import { InjectRepository } from '@nestjs/typeorm';
~~~~~~~~~~~~~~~~~
src/modules/v1/users/users.repository.ts:3:28 - error TS2307: Cannot find module 'typeorm/index' or its corresponding type declarations.
3 import { Repository } from 'typeorm/index';
~~~~~~~~~~~~~~~
src/modules/v1/users/users.repository.ts:4:32 - error TS2307: Cannot find module 'typeorm/find-options/FindConditions' or its corresponding type declarations.
4 import { FindConditions } from 'typeorm/find-options/FindConditions';
In short how do i invalidate/delete all access tokens for a user on the server so any new request should have a "token expired" response.
At the moment after logout, or logout all - a request with old bearer token is still valid.
Also in the redis store i see that the email/refresh token pair is deleted.
Hello really great work here! I am using an M1 Mac and after having to force install node modules npm run start:dev does not work which is a separate issue and I then try the docker-compose up command also and get this below. I think it's just the git installation that is the issue.
[5/6] RUN apt-get install -y git:
#10 0.651 Reading package lists...
#10 0.657 Building dependency tree...
#10 0.658 Reading state information...
#10 0.658 E: Unable to locate package git
executor failed running [/bin/sh -c apt-get install -y git]: exit code: 100
ERROR: Service 'app' failed to build : Build failed
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.