NestJS doesn't start within apps - nestjs

I recently started using turborepo.
I added a new app into /apps directory, called api by doing the following
$ cd apps
$ nest new api
Now if I try and run nest api
$ cd api
$ yarn start:dev
It fails with following error,
../../node_modules/#types/react-dom/node_modules/#types/react/index.d.ts:3100:14 - error type LibraryManagedAttributes<C, P>dAttributes'.
~~~~~~~~~~~~~~~~~~~~~~~~
3100
../../node_modules/#types/react/index.d.ts:3100:14
3100 type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
~~~~~~~~~~~~~~~~~~~~~~~~
'LibraryManagedAttributes' was also declared here.
../../node_modules/#types/react/index.d.ts:3100:14 - error TS2300: Duplicate identifier 'LibraryManagedAttributes'.
3100 type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
~~~~~~~~~~~~~~~~~~~~~~~~
../../node_modules/#types/react-dom/node_modules/#types/react/index.d.ts:3100:14
3100 type LibraryManagedAttributes<C, P> = C extends React.MemoExoticComponent<infer T> | React.LazyExoticComponent<infer T>
~~~~~~~~~~~~~~~~~~~~~~~~
'LibraryManagedAttributes' was also declared here.
[4:35:02 PM] Found 2 errors. Watching for file changes.
Help!

I got it to work after changing the tsconfig.json in apps/api
{
"extends": "tsconfig/base.json",
"include": [
"./**/*.ts"
],
"exclude": [
"node_modules"
],
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true
}
}

Related

Prevent tsc type checking projects in node_modules folder?

I am running into an issue whereby tsc is insisting on type-checking files in the node_modules folder, resulting in errors such as:
> my-project#0.0.0 build:ts
> tsc --project tsconfig.json
node_modules/mongoose/types/query.d.ts:619:34 - error TS1144: '{' or ';' expected.
619 toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
~
node_modules/mongoose/types/query.d.ts:619:45 - error TS1005: '>' expected.
619 toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
~
node_modules/mongoose/types/query.d.ts:619:77 - error TS1109: Expression expected.
619 toConstructor(): typeof Query<ResultType, DocType, THelpers, RawDocType>;
~
node_modules/mongoose/types/query.d.ts:622:19 - error TS1109: Expression expected.
622 update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType> | UpdateWithAggregationPipeline, options?: QueryOptions<DocType> | null, callback?: Callback<UpdateWriteOpResult>): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType>;
This has only just started happening and I am trying to work out the cause and the resolution. The skipLibCheck parameter doesn't seem to be having any impact.
My tsconfig.json is as follows:
{
"compilerOptions": {
"lib": [
"es2020"
],
"module": "commonjs",
"experimentalDecorators": true,
"moduleResolution": "node",
"sourceMap": true,
"strict": false,
"target": "es2020",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"typeRoots": [
"node_modules/#types"
],
"outDir": "dist",
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src/**/*.ts"
],
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
"ts-node": {
"files": true,
}
}
Version info:
tsc 4.5.5 (provided by typescript#4.5.5)
node v16.10.0
The issue turned out to be a Typescript version mismatch, where we were using an older version than one of our dependencies.
The project was using Typescript 4.5.5 and one of the dependencies, in this case mongoose, changed to using Typescript 4.8.x in their 6.7.0 release. I didn't catch this until I checked the node_modules/mongoose/package.json and noticed that package.json specified:
"mongoose": "^6.1.2"
This meant the minor version was free to change, since it was an equivalent version, resulting in a silent breaking change appearing in our project.
This means I have two solutions:
Upgrade the Typescript version, used by the project
Use the '~' for the mongoose version to stay in 6.1.x
The first approach is what makes sense medium to long term, but the second one will get us unblocked the fastest. This is partly because upgrading the TS version will present the risk of unknowns, which we aren't ready for.

Ora library doesn't compile with typescript

I am trying to build a CLI with nodejs and i tried to add some spinners in the command line using Ora. Unfortunately when i run tsc to build my JS 26 errors are thrown :
........
node_modules/ora/index.d.ts:269:9 - error TS1005: ';' expected.
269 frame(): string;
~
node_modules/ora/index.d.ts:270:1 - error TS1128: Declaration or statement expected.
270 }
~
Found 26 errors.
this my tsconfig file :
{
"compilerOptions": {
"target": "es5",
"lib": ["es2017", "es2015", "dom", "es6"],
"module": "commonjs",
"outDir": "./bin",
"sourceMap": false,
"strict": true,
"moduleResolution": "node"
},
"include": ["src/**.ts"],
"exclude": ["node_modules"]
}
I tried importing the module in multiple ways but it always seems to fail the build. thank you.

TypeScript compilation error, importing non default interface with curly braces

When compiling my TypeScript project, the compiler is throwing the following error:
node_modules/#types/domutils/index.d.ts:6:10 - error TS2614: Module '"../../domhandler/lib"' has no exported member 'DomElement'. Did you mean to use 'import DomElement from "../../domhandler/lib"' instead?
The offending line is:
import { DomElement } from "domhandler";
The problem is, in the typing file it is trying to import from, the DomElement interface is a non default exported interface as follows:
export interface DomElement {
attribs?: {[s: string]: string};
children?: DomElement[];
data?: any;
name?: string;
next?: DomElement;
parent?: DomElement;
prev?: DomElement;
type?: string;
}
If I remove the curly braces it does in fact work, but that seems problematic to me:
I was under the impression that only default exports can be imported without curly braces. Why is this import required without curly braces?
This issue is occurring in type definitions in the node-modules folder as provided by DefinitelyTyped. I do not want to change a dependency file. There are no related open issues in Github, so I assume it does work. In fact it works for a colleague with an older version of Node (v8) but that doesn't seem like it should make a difference.
Versions:
Node.js - 12.14.0
List item
TypeScript 3.7.2 (also tested not working on 3.7.4)
Type definitions for domhandler 2.4 (https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/domhandler)
Type definitions for domutils 1.7 (https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/domutils)
UPDATE
Here is my tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
Based on info from aluanhaddad at GitHub I managed to get it compiling (and working), though I don't like the solution (because it's actually turning any checking for that module off).
I have removed typings to sanitize-html (and related domhandler etc.). TSC cries that it doesn't know "sanitize-html" module, so I've added a dummy module declaration inside my src folder.
src/sanitize-html.d.ts
declare module 'sanitize-html';
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"lib": [
"es6",
"dom"
],
"include": [
"src/**/*",
"index.ts"
],
"exclude": [
"**/*.spec.ts"
]
}
build command:
tsc

Angular 2 AoT compilation with subfolders

My folder structure is as follows:
root
|
|- app
|
|- feature1
| |
| |- feature1.component.ts
| |- feature1.component.html
|- feature2
|- feature3
My app works when running "npm start".
I am following the official docs ( https://angular.io/docs/ts/latest/cookbook/aot-compiler.html ) on how to do this, but ngc seems to get confused by this folder structure.
I get this error when running "node_modules/.bin/ngc -p tsconfig-aot.json":
Error: Compilation failed. Resource file not found: /mnt/intenso/code/my-angular2/app/dashboard/app/dashbo ard/dashboard.component.html
at Object.get (/mnt/intenso/code/my-angular2/node_modules/#angular/compiler-cli/src/codegen.js:71:27)
at DirectiveNormalizer._fetch (/mnt/intenso/code/my-angular2/node_modules/#angular/compiler/bundles/co mpiler.umd.js:13661:45)
at DirectiveNormalizer.normalizeTemplateAsync (/mnt/intenso/code/my-angular2/node_modules/#angular/com piler/bundles/compiler.umd.js:13704:23)
at DirectiveNormalizer.normalizeDirective (/mnt/intenso/code/my-angular2/node_modules/#angular/compile r/bundles/compiler.umd.js:13679:46)
at /mnt/intenso/code/my-angular2/node_modules/#angular/compiler/bundles/compiler.umd.js:13142:139
at Array.map (native)
at /mnt/intenso/code/my-angular2/node_modules/#angular/compiler/bundles/compiler.umd.js:13142:80
at Array.map (native)
at OfflineCompiler._compileSrcFile (/mnt/intenso/code/my-angular2/node_modules/#angular/compiler/bundl es/compiler.umd.js:13132:31)
at /mnt/intenso/code/my-angular2/node_modules/#angular/compiler/bundles/compiler.umd.js:13116:72
Compilation failed
It seems like it expects all my feature# folders to not exist, and have a completely flat structure - something i would like to avoid. How do i achieve this?
My tsconfig-aot.json:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"files": [
"app/app.module.ts",
"app/main.ts"
],
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit" : true
}
}

Using electron api in typescript

I want to use electron from typescript.
I installed dt~gihub-electron and node type definitions via typings.
But when I try to compile I get the following error:
typings/globals/github-electron/index.d.ts(5,29): error TS2304: Cannot
find name 'NodeJS'.
here is my tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"outDir": "dist/frontend/app",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/globals"
],
"files": [
"typings/index.d.ts"
]
}
and typings/index.d.ts:
/// <reference path="globals/es6-shim/index.d.ts" />
/// <reference path="globals/node/index.d.ts" />
/// <reference path="globals/github-electron/index.d.ts" />
thank you for any help.
I cam up with as solution myself.
It was the case that I installed the node typings from the env source and the electron typings form the dt source.
I uninstalled the node typings and reinstalled them from the dt source, and now it is working.
But I am a little bit confused, because the d.ts files from both souces seem to look the same, and as far as I know only the d.ts files matter.

Resources