I am using akveo backend bundle that I bought, and while everything seems to be working fine in development mode starting in production gives me following errors, I am new to nestjs itself.
Anyone know what's going here?
node_modules/#nestjs/core/adapters/http-adapter.d.ts:5:31 - error TS2420: Class 'AbstractHttpAdapter<TServer, TRequest, TResponse>' incorrectly implements interface 'HttpServer<TRequest, TResponse>'.
Property 'status' is missing in type 'AbstractHttpAdapter<TServer, TRequest, TResponse>' but required in type 'HttpServer<TRequest, TResponse>'.
5 export declare abstract class AbstractHttpAdapter<TServer = any, TRequest = any, TResponse = any> implements HttpServer<TRequest, TResponse> {
~~~~~~~~~~~~~~~~~~~
node_modules/#nestjs/common/interfaces/http/http-server.interface.d.ts:26:5
26 status(response: any, statusCode: number): any;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'status' is declared here.
node_modules/#nestjs/core/application-config.d.ts:2:39 - error TS2307: Cannot find module '#nestjs/common/interfaces/configuration-provider.interface'.
2 import { ConfigurationProvider } from '#nestjs/common/interfaces/configuration-provider.interface';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/#nestjs/core/guards/guards-context-creator.d.ts:3:39 - error TS2307: Cannot find module '#nestjs/common/interfaces/configuration-provider.interface'.
3 import { ConfigurationProvider } from '#nestjs/common/interfaces/configuration-provider.interface';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/#nestjs/core/interceptors/interceptors-context-creator.d.ts:2:39 - error TS2307: Cannot find module '#nestjs/common/interfaces/configuration-provider.interface'.
2 import { ConfigurationProvider } from '#nestjs/common/interfaces/configuration-provider.interface';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/#nestjs/core/nest-application.d.ts:24:5 - error TS2416: Property 'getHttpAdapter' in type 'NestApplication' is not assignable to the same property in base type 'INestApplication'.
Type '() => AbstractHttpAdapter<any, any, any>' is not assignable to type '() => HttpServer<any, any>'.
Property 'status' is missing in type 'AbstractHttpAdapter<any, any, any>' but required in type 'HttpServer<any, any>'.
24 getHttpAdapter(): AbstractHttpAdapter;
~~~~~~~~~~~~~~
node_modules/#nestjs/common/interfaces/http/http-server.interface.d.ts:26:5
26 status(response: any, statusCode: number): any;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'status' is declared here.
Found 5 errors.
I am using tsc -p tsconfig.build.json command to build it with tsconfig.build.json:
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "**/*spec.ts"]
}
and tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./"
},
"exclude": ["node_modules"]
}
I expect that this config should compile typescript code to javascript which then I would run with node dist/main.js command. Which it actually does. But I am worried about the typescript compiler errors.
Not sure without the code but got similar mismatches once upon a time in nest core packages. Check out package.json and ensure that all #nest packages have the same version, as sometimes they have 'breaking' changes even if it wasn't major release.
For an abstract example, something like that gave me errors related to core when building production:
"#nestjs/common": "6.6.0", // notice the core/common does not match, it should be bumped
"#nestjs/core": "6.6.2",
Related
I am trying to follow the following guide to make a custom task in azure devops https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops
When I install both 'azure-pipelines-task-lib' & 'vss-web-extension-sdk'
and have a single typescript file that requires the task-lib, like the guide suggests, I get tons of typescript errors.
package.json
"dependencies": {
"azure-pipelines-task-lib": "^3.1.9",
"typescript": "^4.4.3",
"vss-web-extension-sdk": "^5.141.0"
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "es6",
"rootDir": "src/",
"outDir": "dist/",
"types": [
"vss-web-extension-sdk"
]
},
"files": [
"src/index.ts"
]
}
index.ts
import tl = require('azure-pipelines-task-lib/task');
export function Foo() {
return "BAR"
}
File structure
Root
tsconfig.json
package.json
src
index.ts
dist
index.js
Errors
https://imgur.com/4aNJetK
node_modules/#types/node/module.d.ts:2:5 - error TS2300: Duplicate identifier 'mod'.
2 export = NodeJS.Module;
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/#types/requirejs/index.d.ts:38:14
38 export = mod;
~~~
'mod' was also declared here.
node_modules/#types/requirejs/index.d.ts:38:14 - error TS2300: Duplicate identifier 'mod'.
38 export = mod;
~~~
node_modules/#types/node/module.d.ts:2:5
2 export = NodeJS.Module;
~~~~~~~~~~~~~~~~~~~~~~~
'mod' was also declared here.
node_modules/#types/requirejs/index.d.ts:422:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type
'NodeRequire', but here has type 'Require'.
422 declare var require: Require;
~~~~~~~
node_modules/#types/node/globals.d.ts:213:13
213 declare var require: NodeRequire;
~~~~~~~
'require' was also declared here.
node_modules/vss-web-extension-sdk/typings/vss.d.ts:3168:13 - error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NodeRequire', but here has type 'Require'.
3168 declare var require: Require;
~~~~~~~
node_modules/#types/node/globals.d.ts:213:13
213 declare var require: NodeRequire;
~~~~~~~
'require' was also declared here.
Can someone provide me with ANY working example of compiling typescript when these libraries are installed?
Im trying to import socket.io-client into my project but the import line
import * as io from 'socket.io-client';
is throwing the following error
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,204): '>' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,239): '(' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,260): ',' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,265): ',' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,296): '(' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,313): ',' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,321): Expression expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (37,49): ';' expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (37,92): Expression expected.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (21,86): Cannot find name 'Parameters'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,212): 'EventNames' only refers to a type, but is being used as a value here.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,241): Cannot find name 'ReservedEvents'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,256): Cannot find name 'Ev'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,262): Cannot find name 'Ev'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,273): 'EventNames' only refers to a type, but is being used as a value here.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,298): Cannot find name 'UserEvents'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,309): Cannot find name 'Ev'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (30,315): Cannot find name 'never'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (37,58): Cannot find name 'never'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (37,94): Cannot find name 'T'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (51,31): Class 'StrictEventEmitter<ListenEvents, EmitEvents, ReservedEvents>' incorrectly extends base class 'Emitter<string>'.
Types of property 'on' are incompatible.
Type '<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>(ev: Ev, listener: [Ev]) => this' is not assignable to type '(event: string, listener: Function) => Emitter<string>'.
Types of parameters 'listener' and 'listener' are incompatible.
Type 'Function' is not assignable to type '[any]'.
Property '0' is missing in type 'Function'.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (72,53): A rest parameter must be of an array type.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/typed-events.d.ts (82,75): A rest parameter must be of an array type.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/socket.d.ts (48,9): An accessor cannot be declared in an ambient context.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/socket.d.ts (73,53): A rest parameter must be of an array type.
ERROR in C:/Users/USER/Desktop/VSCProjects/CellularAss8/client/node_modules/socket.io-client/build/socket.d.ts (184,9): An accessor cannot be declared in an ambient context.
After digging around for a bit I found that while being in angular debug mode, if I comment the import line out, save, uncomment and save the code run perfectly in debug mode.
Is there anyway to fix it so the import will work without the steps i mention above?
Angular version is 4.4.6
and socket.io-client version is 1.7.3
and here is the tsconfig.json file
{
"compileOnSave": false,
"compilerOptions": {
"esModuleInterop": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": ["node_modules/#types"],
"lib": ["es2017", "dom"]
},
"allowSyntheticDefaultImports": true
}
You are not using socket.io-client in version 1.7.3 but rather version ^4.1.3. That one defacto creates dependency on typescript 4 thanks to its packed type definition files but your project compiles with typescript ~2.3.3. Hence the error you are getting.
Make sure to install the correct version with npm i -S socket.io-client#1.7.3. It doesn't pack its own type definitions though (so it creates no dependency on typescript), so you will also need to install #types/socket.io-client#1 to get the types.
I'm not sure about the issue you mention but I might be able to provide a workaround.
You can try using this package instead https://www.npmjs.com/package/ngx-socket-io while working with Angular and Socket.io. I've used it in the past and it works well, it might solve your problem.
Simply install it and then configure it. Something like:
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const config: SocketIoConfig = { url: 'http://localhost:8988', options: {} };
#NgModule({
declarations: [AppComponent],
imports: [BrowserModule, SocketIoModule.forRoot(config)],
bootstrap: [AppComponent],
})
export class AppModule {}
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
this one is head scratcher for me. Can't figure this one out... probably need some fresh eye on the matter
I've got the following code
import express from 'express';
import { isFunction } from 'lodash';
export class Server {
private _server = express();
private _namespace = '/api/v1';
public constructor(private _port: number) {}
public addRoute({ path, handler, method }): this {
var requestHandler = this._server[String(method).toLowerCase()];
if (false === isFunction(requestHandler)) throw new Error('Invalid HTTP method');
requestHandler(path, handler);
return this;
}
}
And I keep getting the same errors, which to me makes no sense at all...
TSError: тип Unable to compile TypeScript:
src/server/main.ts:21:14 - error TS2339: Property '_port' does not exist on type 'Server'.
21 this._port = _port;
~~~~~
src/server/main.ts:22:14 - error TS2339: Property '_server' does not exist on type 'Server'.
22 this._server = express_1.default();
~~~~~~~
src/server/main.ts:23:14 - error TS2339: Property '_namespace' does not exist on type 'Server'.
23 this._namespace = '/api/v1';
~~~~~~~~~~
src/server/main.ts:34:35 - error TS2339: Property '_server' does not exist on type 'Server'.
34 var requestHandler = this._server[String(method).toLowerCase()];
~~~~~~~
This is just bonkers to me...
I'm using typescript 3.6.3, running on node 12.8.1 and using ts-node 8.4.1 to plugin TS support
I've pasted the code on type the whole code on TS playground. Made some changes to remove the imports and undefined functions, but overall the above errors do not appear, so I'm kind stomped... if anyone would be kind to point me in the direction of solving this problem that would be fantastic :)
Also, here is my tsconfig.json
{
"compilerOptions": {
"noImplicitThis": false,
"rootDir": "src",
"typeRoots": ["node_modules/#types", "#types"],
"lib": ["es6"],
"strict": true,
"strictPropertyInitialization": false,
"strictFunctionTypes": true,
"esModuleInterop": true,
"target": "es6",
"noImplicitAny": false,
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": false,
"pretty": true,
"outDir": "build",
"alwaysStrict": false,
"noImplicitReturns": true,
"noStrictGenericChecks": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"suppressImplicitAnyIndexErrors": true,
"preserveConstEnums": false,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"include": ["./**/*.ts"],
"compileOnSave": true,
"exclude": ["node_modules"]
}
I've finally figured out what has happened. A clue was that the errors reported has been reporting errors on an already transpiled code. Typescript was ran against a JS code...
What the issue was I was starting the server using nodemon and requiring ts-node again manually. This was the command I've been using
nodemon --ext ts --delay 100ms -r ts-node/register src/app.ts
And it was fine (and even needed) when on my previous project which used nodemon 1.18.9.
But, when I was setting up a new project I've automatically upgraded nodemon to version 1.19.2 and as one can check in nodemon v1.19.0 release notes the TS has been added to default exec path. So, once the nodemon figures out you are running TS files it will change the final node command
FROM
node -r ts-node/register src/app.ts
TO
ts-node -r ts-node/register src/app.ts
Which means that the Typescript will be ran twice and the second time it will ran against an already finished transpiled code a.k.a JS code.
Anyways, once I've changed the start-up command to
nodemon --ext ts --delay 100ms src/app.ts
it all worked as expected.
Hope this helps someone should anyone ran into a similar problem
I also had this issue and spent a long time trying to figure out what was wrong. I'm going to leave this here for people who might run into this in the future. It turns out I had a ts-node re-register as part of my code to get a Typescript Worker thread working. If you have this issue, double check if you using ts-node in the code.
const path = require("path");
require("ts-node").register(); // <-- BAD
require(path.resolve(__dirname, "./worker.ts"));
I'm using typescript in a web project. I use awesome-typescript-loader as a webpack loader. I am getting error when building my project:
ERROR in [at-loader] ./node_modules/#types/node/index.d.ts:82:15
TS2451: Cannot redeclare block-scoped variable 'custom'.
ERROR in [at-loader] ./node_modules/#types/node/index.d.ts:85:15
TS2451: Cannot redeclare block-scoped variable 'custom'.
ERROR in [at-loader] ./node_modules/#types/node/ts3.2/util.d.ts:7:15
TS2451: Cannot redeclare block-scoped variable 'custom'.
ERROR in [at-loader] ./node_modules/#types/node/ts3.2/util.d.ts:10:15
TS2451: Cannot redeclare block-scoped variable 'custom'.
I initiated a complete new folder with just typescript and #types/typescript installed, I can still see the same error complained by visual studio code.
Versions below:
"dependencies": {
"#types/node": "^11.13.6",
"typescript": "^3.4.4"
}
As the error showed above, I found
in index.d.ts:
declare module "util" {
namespace inspect {
const custom: symbol;
}
namespace promisify {
const custom: symbol;
}
namespace types {
function isBigInt64Array(value: any): boolean;
function isBigUint64Array(value: any): boolean;
}
}
in util.d.ts:
declare module "util" {
namespace inspect {
const custom: unique symbol;
}
namespace promisify {
const custom: unique symbol;
}
namespace types {
function isBigInt64Array(value: any): value is BigInt64Array;
function isBigUint64Array(value: any): value is BigUint64Array;
}
}
We can see custom is indeed being re-declared in index.d.ts and util.d.ts.
So my question is how to fix this issue? Is this a bug of #types/node?
I was facing the same issue. Removing reference to node in tsconfig fixed the issue for me.
Sample tsconfig.
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"outDir": "dist",
"sourceMap": true
},
"files": [
// "./node_modules/#types/node/index.d.ts",
"./node_modules/#types/express/index.d.ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"lib": [
"es2017"
]
}
My problem is that I accidentally included node_modules/#types. Fixed by comment it out like this:
"include": ["src/**/*.ts","__tests__/**/*.ts"/*, "node_modules/#types"*/]
I had the same issue, but the error message was misleading just because of something wrong cached. I tried many things, but finally solved it by removing npm_modules, clearing cache, and new installation:
npm cache clean --force
npm install
I added this piece of code twice in protractor.conf.js file
require('ts-node').register({
project: require('path').join(__dirname, './tsconfig.e2e.json')
});