Error building angular2 library - node.js

This is my tsconfig-build.json used for taking the build
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"sourceMap": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"outDir": "../dist"
},
"files": ["./index.ts"],
"angularCompilerOptions": {
"genDir": "compiled",
"strictMetadataEmit": true,
"skipTemplateCodegen": true
},
"exclude": [
"node_modules",
"dist",
"gh-pages",
"**/*.ngfactory.ts",
"**/*.shim.ts",
"**/*.spec.ts"
]
}
this is the script in my package.json file
"scripts": {
"prebuild": "rimraf ./dist ./compiled",
"build": "ngc -p ./src/tsconfig-build.json"
},
While running the script npm run build , Im getting missing error listed below.
../node_modules/#angular/core/src/di/reflective_provider.d.ts(87,123): error TS2304: Cannot find name 'Map'.
../node_modules/#angular/core/src/di/reflective_provider.d.ts(87,165): error TS2304: Cannot find name 'Map'.
../node_modules/rxjs/Observable.d.ts(58,60): error TS2693: 'Promise' only refers to a type, but is being used as a value here.
../node_modules/rxjs/Observable.d.ts(73,59): error TS2693: 'Promise' only refers to a type, but is being used as a value here.
../node_modules/#angular/core/src/change_detection/differs/iterable_differs.d.ts(14,48): error TS2304: Cannot find name 'Iterable'.
../node_modules/#angular/core/src/change_detection/differs/keyvalue_differs.d.ts(22,18): error TS2304: Cannot find name 'Map'.
../node_modules/#angular/core/src/change_detection/differs/default_iterable_differ.d.ts(12,32): error TS2304: Cannot find name 'Iterable'.../node_modules/#angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,16): error TS2304: Cannot find name 'Map'.
../node_modules/#angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(32,16): error TS2304: Cannot find name 'Map'.
../node_modules/#angular/common/src/directives/ng_class.d.ts(48,34): error TS2304: Cannot find name 'Set'.
../node_modules/ionic-angular/util/module-loader.d.ts(13,14): error TS2304: Cannot find name 'Map'.
../node_modules/ionic-angular/util/module-loader.d.ts(14,18): error TS2304: Cannot find name 'Map'.
../node_modules/ionic-angular/util/base-input.d.ts(2,38): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/util/base-input.d.ts(3,27): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/components/datetime/datetime.d.ts(2,38): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/components/input/input.d.ts(2,27): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/components/range/range.d.ts(2,38): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/components/searchbar/searchbar.d.ts(2,27): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/components/segment/segment.d.ts(2,27): error TS2307: Cannot find module '#angular/forms'.
../node_modules/ionic-angular/gestures/gesture-config.d.ts(1,37): error TS2307: Cannot find module '#angular/platform-browser'.
Its a simple angular directive for ionic app,What might be the reason
for above missing statements ?
Thanks

Change your tsconfig.json as
"compilerOptions": {
"target": "es5",
"lib": ["es5", "es6", "dom"], <--- this
...
}

Related

Typescript compiling errors using 'vss-web-extension-sdk' & 'azure-pipelines-task-lib'

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?

"error TS2304: Cannot find name 'Long'" when compiling typescript with google api libraries

I just added "#google-cloud/logging-winston":"2.1.0", in my pacakge.json and when I compile I get the following errors. I have seen this with other google libraries occasionally, and its root cause is most likely deeper in the stack in automatic generated types from protobuf definitions.
../node_modules/#google-cloud/logging/build/proto/logging.d.ts:1434:32 - error TS2304: Cannot find name 'Long'.
1434 line?: (number|Long|null);
~~~~
../node_modules/#google-cloud/logging/build/proto/logging.d.ts:1453:38 - error TS2304: Cannot find name 'Long'.
1453 public line: (number|Long);
~~~~
../node_modules/#google-cloud/logging/build/proto/logging.d.ts:1543:39 - error TS2304: Cannot find name 'Long'.
1543 requestSize?: (number|Long|null);
~~~~
../node_modules/#google-cloud/logging/build/proto/logging.d.ts:1549:40 - error TS2304: Cannot find name 'Long'.
1549 responseSize?: (number|Long|null);
~~~~
../node_modules/#google-cloud/logging/build/proto/logging.d.ts:1576:42 - error TS2304: Cannot find name 'Long'.
1576 cacheFillBytes?: (number|Long|null);
Here is how I worked around this issue until it is taken care of.
In your package.json dependencies section add "long":"4.0.0",
In your package.json devDependencies section: add "#types/long":"4.0.0",
Finally, in tsconfig.json (add to tsconfig.app.js if that doesn't work) (or in the tsc command line) add:
{
"compilerOptions": {
...
"types": [
...
"long"
],
...
}
gae123 suggestion did not work for me on typescript version 4.9.4.
I added the following to tsconfig.json. Hope this helps.
"compilerOptions":{
...
"skipLibCheck": true,
}
I solved adding the long packet and #types/long, as gae123 suggested, but now the type is not to add in tsconfig.json but in tsconfig.app.json.
"compilerOptions": {
...
"types": [...,"long"]
}
Thanks gae123!

Starting nestjs in production mode

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",

TS2451: Cannot redeclare block-scoped variable 'custom'

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')
});

Typescript Google API compilation errors

I'm using Typescript, tslint and Google APIs but there's issues compiling in typescript to javascript and I'm not sure why and for some reason I can't find anything specific online about this problem. Google searches don't render good results. I can't find a good example of how your tsconfig should be setup with this library also. So I'm coming here.
I'm running into lots of "Cannot find type definition file" and "Cannot find module" errors when I run tsc.
My file is literally just this line:
import {google} from 'googleapis'
That's it.
When I run tsc it gives me these errors:
$ tsc
node_modules/gaxios/build/src/common.d.ts:1:23 - error TS2688: Cannot find type definition file for 'node'.
1 /// <reference types="node" />
~~~~
node_modules/gaxios/build/src/common.d.ts:3:23 - error TS2307: Cannot find module 'https'.
3 import { Agent } from 'https';
~~~~~~~
node_modules/google-auth-library/build/src/auth/authclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.
16 /// <reference types="node" />
~~~~
node_modules/google-auth-library/build/src/auth/authclient.d.ts:17:30 - error TS2307: Cannot find module 'events'.
17 import { EventEmitter } from 'events';
~~~~~~~~
node_modules/google-auth-library/build/src/auth/googleauth.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.
16 /// <reference types="node" />
~~~~
node_modules/google-auth-library/build/src/auth/googleauth.d.ts:17:21 - error TS2307: Cannot find module 'fs'.
17 import * as fs from 'fs';
~~~~
node_modules/google-auth-library/build/src/auth/googleauth.d.ts:19:25 - error TS2307: Cannot find module 'stream'.
19 import * as stream from 'stream';
~~~~~~~~
node_modules/google-auth-library/build/src/auth/googleauth.d.ts:182:20 - error TS2503: Cannot find namespace 'NodeJS'.
182 _osPlatform(): NodeJS.Platform;
~~~~~~
node_modules/google-auth-library/build/src/auth/jwtaccess.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.
16 /// <reference types="node" />
~~~~
node_modules/google-auth-library/build/src/auth/jwtaccess.d.ts:17:25 - error TS2307: Cannot find module 'stream'.
17 import * as stream from 'stream';
~~~~~~~~
node_modules/google-auth-library/build/src/auth/jwtclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.
16 /// <reference types="node" />
~~~~
node_modules/google-auth-library/build/src/auth/jwtclient.d.ts:18:25 - error TS2307: Cannot find module 'stream'.
18 import * as stream from 'stream';
~~~~~~~~
node_modules/google-auth-library/build/src/auth/refreshclient.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.
16 /// <reference types="node" />
~~~~
node_modules/google-auth-library/build/src/auth/refreshclient.d.ts:17:25 - error TS2307: Cannot find module 'stream'.
17 import * as stream from 'stream';
~~~~~~~~
node_modules/google-auth-library/build/src/crypto/crypto.d.ts:16:23 - error TS2688: Cannot find type definition file for 'node'.
16 /// <reference types="node" />
~~~~
node_modules/google-auth-library/build/src/crypto/crypto.d.ts:32:60 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i #types/node` and then add `node` to the types field in your tsconfig.
32 verify(pubkey: string | JwkCertificate, data: string | Buffer, signature: string): Promise<boolean>;
My tsconfig file is:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"esModuleInterop": true,
"noImplicitAny": false,
"moduleResolution": "node",
"sourceMap": true,
"outDir": "app",
"baseUrl": "./app",
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
My package dependencies are:
"dependencies": {
"googleapis": "^37.2.0",
"mysql": "^2.16.0",
"typescript": "^3.3.3333"
},
"devDependencies": {
"nodemon": "^1.18.10",
"tslint": "^5.12.1"
}
I'm not using the tsc node module (which is deprecated), I'm using typescript v3.3.3
Help would be appreciated! :)
Type errors in 3rd party libraries typings can easily be avoided by either submitting a pull request OR turning on skipLibCheck: true in your tsconfig and wait for them to be fixed.
Hope this helps.

Resources