NestJS taking too long to compile and hot-reload not working - nestjs

I just made a project with nest new new-project but the compilation takes more than 20 minutes.
Also the hot-reload does not detect any file changes and does not reload when I save the file.
I have implemented this - https://docs.nestjs.com/recipes/hot-reload but did not work.
this is what my tsconfig.json file looks like :
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
"resolveJsonModule": true,
"esModuleInterop": true,
}
}
Any pointers is greatly appreciated. Thank you.

By the looks of it it tries to recompile all your node_modules.
Please, add this line to your tsconfig.json:
{
"exclude": ["node_modules"]
}
Alternatively, you can include files you want to compile with this line:
{
"include": ["src/**/*"]
}
For more info you can refer to TypeScript Documentation

Related

Cannot find module 'react' error when using next-auth in nodejs

Works fine in my local environment but when i try to deploy my server getting
Error: Cannot find module 'react'
on /project/src/node_modules/next-auth/react/index.js
it seems like next-auth using React for some parts.
my ts config:
{
"compilerOptions": {
"target": "es2022",
"lib": ["ES2022"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "ES2022",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
},
"exclude": ["node_modules"],
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
}
my package.json:
I've used ts-node --esm for build command

Typescript stopped working with absolute paths

I'm maintain a fork of a repo, during my last update I applied changes however now typescript will not recognize absolute pathing.
I've made no changes to my tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"baseUrl": "src",
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"target": "es5",
"types": ["jest", "node"],
"useUnknownInCatchVariables": false
},
"exclude": ["node_modules", "cypress"],
"include": ["src/**/*"]
}
However now the compiler doesn't recognize paths that looks like so:
import { useIsDarkMode } from 'state/user/hooks'
Something went wrong with the node_modules, after I deleted them and called
yarn clean cache
yarn
Then everything started to work again

experimentalDecorators error in typegrapql

I am currently learning TypeGraphQL and trying to create a basic reslover, my code looks like this:
#Resolver()
class HelloReslover {
#Query(() => String)
async hello(){
return "hello wtold"
}
}
But i got this error:
"Experimental support for decorators is a feature that is subject to
change in a future release. Set the 'experimentalDecorators' option in
your 'tsconfig' or 'jsconfig' to remove this warning."
But my tsconfig file looks like this:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"],
"sourceMap": true,
"outDir": "./dist",
"moduleResolution": "node",
"declaration": false,
"composite": false,
"removeComments": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"baseUrl": ".",
"rootDir": "src"
},
"exclude": ["node_modules"],
"include": ["./src/**/*.tsx", "./src/**/*.ts"]
}
How can I fix this?
I fixed it on my own , here how is I did it:
I deleted everything in tsconfig.json and replaced it whit this code:
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"lib": ["es2018", "esnext.asynciterable"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}

Top level await gives error in build but works on dev

My code works when ran npm run dev but when I build it it gives this error. According to the docs I need target set to ES2017 or higher in tsconfig.json but I am using ESNEXT which I believe is compatible
error
tsconfig.json
{
"compilerOptions": {
"target": "ESNext",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["./src"]
}
Because I was using vite in the question, vite.config.ts is what I should have been looking to edit instead of tsconfig.json
here is the fix to it
vite.config.ts
export default defineConfig({
build: {
minify: 'esbuild',
target: "esnext"
}
})

How can CommonJS and ES6 modules be included in the same repo?

I have a NestJS/Typescript backend where I am trying to use two different third-party services that use different importing formats. The two are below:
PDFTron uses: const { PDFNet } = require('#pdftron/pdfnet-node');
Prisma uses: import { PrismaClient } from '#prisma/client'
I have asked PDFTron support to see if an module import style similar to Prisma works for their service, but they have told me it doesn't. So, how can I use both third parties if PDFTron doesn't work in Typescript files?
For reference, my tsconfig file contains the below:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": "./",
"allowJs": true,
"skipLibCheck": false,
"strict": false,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"tsBuildInfoFile": ".tsbuildinfo"
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

Resources