Class constructor TranslateLoader cannot be invoked without 'new' --- error is showing while running jest test in angular 12 - angular12

Class constructor TranslateLoader cannot be invoked without 'new' --- error is showing while running jest test in angular 12, please someone help me.
"devDependencies": {
"#angular-devkit/build-angular": "~12.0.0",
"#angular/cli": "~12.0.0",
"#angular/compiler-cli": "~12.0.0",
"#fullhuman/postcss-purgecss": "^5.0.0",
"#types/jest": "^29.2.0",
"#types/node": "^12.11.1",
"cssnano": "^5.1.13",
"jest": "^29.2.1",
"jest-preset-angular": "^12.2.2",
"jscat": "0.0.2",
"ngx-translate-testing": "^5.2.0",
"postcss": "^8.4.17",
"postcss-loader": "^7.0.1",
"postcss-preset-env": "^7.8.2",
"postcss-scss": "^4.0.5",
"sass": "^1.55.0",
"typescript": "~4.2.3"
}
Error log:
TypeError: Class constructor TranslateLoader cannot be invoked without 'new'
at new TestTranslateLoader (projects/testing/src/lib/test-translate-loader.service.ts:23:5)
at TranslateTestingModule.get (projects/testing/src/lib/testing.module.ts:95:7)
at R3Injector.Object.<anonymous>.R3Injector.processInjectorType (../packages/core/src/di/r3_injector.ts:366:61)
at ../packages/core/src/di/r3_injector.ts:326:20
at ../packages/core/src/util/array_utils.ts:71:74
at Array.forEach (<anonymous>)
at deepForEach (../packages/core/src/util/array_utils.ts:71:9)
at ../packages/core/src/util/array_utils.ts:71:49
at Array.forEach (<anonymous>)
at deepForEach (../packages/core/src/util/array_utils.ts:71:9)
at ../packages/core/src/util/array_utils.ts:71:49
at Array.forEach (<anonymous>)
at deepForEach (../packages/core/src/util/array_utils.ts:71:9)
at R3Injector.Object.<anonymous>.R3Injector.processInjectorType (../packages/core/src/di/r3_injector.ts:325:9)
at ../packages/core/src/di/r3_injector.ts:147:44
at ../packages/core/src/util/array_utils.ts:71:74
at Array.forEach (<anonymous>)
at deepForEach (../packages/core/src/util/array_utils.ts:71:9)
at new R3Injector (../packages/core/src/di/r3_injector.ts:147:5)
at createInjectorWithoutInjectorInstances (../packages/core/src/di/r3_injector.ts:97:10)
at new NgModuleRef$1 (../packages/core/src/render3/ng_module_ref.ts:54:24)
at R3TestBedCompiler.Object.<anonymous>.R3TestBedCompiler.finalize (../packages/core/testing/src/r3_test_bed_compiler.ts:260:26)
at TestBedRender3.get (../packages/core/testing/src/r3_test_bed.ts:370:43)
at TestBedRender3.Object.<anonymous>.TestBedRender3.inject (../packages/core/testing/src/r3_test_bed.ts:268:25)
at TestBedRender3.Object.<anonymous>.TestBedRender3.createComponent (../packages/core/testing/src/r3_test_bed.ts:325:40)
at Function.Object.<anonymous>.TestBedRender3.createComponent (../packages/core/testing/src/r3_test_bed.ts:177:33)
at src/app/shared/components/translate/translate.component.spec.ts:23:23
at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:409:30)
at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:3830:43)
at _ZoneDelegate.Object.<anonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:408:56)
at Zone.Object.<anonymous>.Zone.run (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:169:47)
at Object.wrappedFunc (node_modules/zone.js/bundles/zone-testing-bundle.umd.js:4330:34)

Related

ERROR Error: Uncaught (in promise): TypeError: i.BehaviorSubject is not a constructor in Angular 10 SSR

I'm getting this issue after build successfully and run on browser with angular universal
Here is my package json :
{
"name": "ssr",
"version": "1.0.0",
"private": true,
"dependencies": {
"#angular/animations": "10.0.5",
"#angular/cdk": "10.1.0",
"#angular/common": "10.0.5",
"#angular/compiler": "10.0.5",
"#angular/core": "10.0.5",
"#angular/fire": "^6.0.2",
"#angular/forms": "10.0.5",
"#angular/http": "^7.2.16",
"#angular/localize": "^10.0.5",
"#angular/material": "10.1.0",
"#angular/material-moment-adapter": "10.1.0",
"#angular/platform-browser": "10.0.5",
"#angular/platform-browser-dynamic": "10.0.5",
"#angular/platform-server": "^10.0.5",
"#angular/router": "10.0.5",
"#ng-bootstrap/ng-bootstrap": "^7.0.0",
"#ng-toolkit/universal": "^8.1.0",
"#nguniversal/express-engine": "^10.0.1",
"#types/jquery": "^3.5.1",
"#types/node": "^8.10.62",
"angular-in-memory-web-api": "^0.11.0",
"angular-ng-autocomplete": "^2.0.1",
"classlist.js": "^1.1.20150312",
"codelyzer": "^6.0.0",
"core-js": "2.6.9",
"crypto-js": "^3.3.0",
"express": "^4.15.2",
"firebase": "^7.17.1",
"hammerjs": "^2.0.8",
"jquery": "^3.5.1",
"localstorage-polyfill": "^1.0.1",
"moment": "2.24.0",
"ng2-slim-loading-bar": "^4.0.0",
"ng5-slider": "^1.1.14",
"ngx-order-pipe": "^2.0.4",
"ngx-pagination": "^3.2.1",
"ngx-spinner": "^10.0.1",
"rxjs": "^6.6.0",
"rxjs-compat": "^6.6.0",
"sweetalert2": "^8.19.0",
"tslib": "^1.13.0",
"web-animations-js": "^2.3.2",
"whatwg-fetch": "^3.2.0",
"zone.js": "0.10.3"
},
I just updated my project to Angular 10 and started facing this issue.
What i did was , wherever I had BehaviorSubject imports ,
i changed them from import { BehaviorSubject } from "rxjs/Rx"; to import { BehaviorSubject } from "rxjs";
This makes production build work without any error.
I got solution, use rxjs-tslint and migrate all rxjs syntax : https://www.npmjs.com/package/rxjs-tslint
I am able to solve this by using the build command as ng build --configuration=prod --aot= false --build-optimizer=false. Application is up and running for us now. But it's a work around only. We are trying to check few more ways without setting optimiser to false.Will update you.
I guess your question is solved,
I fixed it using ng build instead of ng build --prod. I am now investigating why the --prod command line compile my app differently
I guess your question is solved,
I fixed it using ng build instead of ng build --prod. I am now investigating why the --prod command line compile my app differently

#react-native-firebase breaking unit tests

I installed v6 of #react-native-firebase, it's working as expected but when I try to run a unit test I get the following error:
Jest encountered an unexpected token
Details:
/node_modules/#react-native-firebase/database/lib/index.js:18
import { isBoolean, isNumber, isString } from '#react-native-firebase/app/lib/common';
^
SyntaxError: Unexpected token {
I tried adding #react-native-firebase/database & #react-native-firebase/app to jest config transformIgnorePatterns and get the following error:
Test suite failed to run
Invariant Violation: Native module cannot be null.
at invariant (node_modules/invariant/invariant.js:40:15)
at RNFBNativeEventEmitter.NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:36:7)
at new RNFBNativeEventEmitter (node_modules/#react-native-firebase/app/lib/internal/RNFBNativeEventEmitter.js:24:5)
at Object.<anonymous> (node_modules/#react-native-firebase/app/lib/internal/RNFBNativeEventEmitter.js:48:16)
at Object.<anonymous> (node_modules/#react-native-firebase/app/lib/internal/registry/nativeModule.js:21:1)
I also tried mocking the module with Jest like so:
import * as FBCommon from '#react-native-firebase/app/lib/common'
jest.mock(FBCommon, () => {
return () => ({
isBoolean: jest.fn(),
isNumber: jest.fn(),
isString: jest.fn()
})
});
and like this:
jest.mock('#react-native-firebase/database', () => {
return () => ({
ref: jest.fn()
})
});
but get the same error, any suggestions?
my package.json:
{
"name": "Project",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"#react-native-community/push-notification-ios": "^1.0.6",
"#react-native-firebase/app": "^6.3.1",
"#react-native-firebase/database": "^6.3.1",
"#react-native-firebase/messaging": "^6.3.1",
"axios": "^0.19.0",
"base-64": "^0.1.0",
"blinkid-react-native": "^5.2.0",
"firebase": "^7.6.0",
"lodash": "^4.17.15",
"mobx": "^5.15.0",
"mobx-persist": "^0.4.1",
"mobx-react": "^6.1.4",
"react": "16.9.0",
"react-native": "0.61.4",
"react-native-auth0": "^2.1.0",
"react-native-collapsible": "^1.5.1",
"react-native-config": "^0.12.0",
"react-native-confirmation-code-input": "^1.0.4",
"react-native-datepicker": "^1.7.2",
"react-native-device-info": "^5.4.1",
"react-native-elements": "^1.2.7",
"react-native-freshchat-sdk": "^2.3.0",
"react-native-gesture-handler": "^1.5.2",
"react-native-in-app-notification": "^3.0.1",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-phone-input": "^0.2.4",
"react-native-picker-select": "^6.3.3",
"react-native-push-notification": "^3.1.9",
"react-native-reanimated": "^1.4.0",
"react-native-screens": "^1.0.0-alpha.23",
"react-native-signature-capture": "^0.4.10",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^8.0.3",
"react-navigation": "^4.0.10",
"react-navigation-stack": "^1.10.3"
},
"devDependencies": {
"#babel/core": "^7.7.2",
"#babel/runtime": "^7.7.2",
"#react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"babel-plugin-module-resolver": "^4.0.0",
"chai": "^4.1.2",
"chai-enzyme": "1.0.0-beta.0",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^6.6.0",
"jest": "^24.9.0",
"jsdom": "15.2.1",
"jsdom-global": "3.0.2",
"metro-react-native-babel-preset": "^0.57.0",
"react-dom": "^16.12.0",
"react-test-renderer": "16.9.0",
"sinon": "^7.2.2"
},
"jest": {
"preset": "react-native",
"setupFilesAfterEnv": [
"./setUpTests.js"
],
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|#react-native-firebase/database|#react-native-firebase/app|react-clone-referenced-element|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|sentry-expo|native-base))"
]
}
}
You could mock firebase database by creating a mock module in a mocks directory like this:
mkdir -p __mocks__/#react-native-firebase/database
touch index.js
And use jest mocking functions in index.js for the firebase version and database functionalities to test. Something along these lines:
const database = {
functionality1: jest.fn(() => ({
propertyExample1: jest.fn(() => Promise.resolve(true)),
...
})),
...
functionality2: jest.fn(() => ({
property2: jest.fn(() => Promise.resolve(true)),...
})),
};
export default database;
This occurs because the native emitter isn't properly mocked by the library. Adding the following snippet at the top of your tests can resolve this by ensuring the module isn't null.
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
I solved the issue creating jest.setup.js file with the content:
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
And then in package.json inside jest
"setupFiles": ["./yourPath/jest.setup.js"],

ionic - Firebase issue

Getting the following error while creating the build.Else not having any problem.
Any solutions to resolve this issue.
Currently using following congfiguration...'
"#angular/animations": "5.2.11",
"#angular/common": "5.2.11",
"#angular/compiler": "5.2.11",
"#angular/compiler-cli": "5.2.11",
"#angular/core": "5.2.11",
"#angular/fire": "^5.2.3",
"#angular/forms": "5.2.11",
"#angular/http": "5.2.11",
"#angular/platform-browser": "5.2.11",
"#angular/platform-browser-dynamic": "5.2.11",
"#ionic-native/core": "~4.20.0",
"#ionic-native/in-app-browser": "^4.20.0",
"#ionic-native/splash-screen": "~4.20.0",
"#ionic-native/status-bar": "~4.20.0",
"#ionic/storage": "2.2.0",
"#ngx-translate/core": "^9.1.1",
"#ngx-translate/http-loader": "^2.0.1",
"angular-bottom-sheet": "^1.2.5",
"angular-material": "^1.1.20",
"angular2": "^2.0.0-beta.21",
"angularfire2": "^5.0.0-rc.6",
"call-number": "^1.0.1",
"cordova-android": "^7.0.0",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-inappbrowser": "^3.1.0",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.1.3",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"firebase": "^7.6.1",
"ionic-angular": "3.9.5",
"ionicons": "3.0.0",
"promise-polyfill": "^8.1.3",
"rxjs": "^6.0.0",
"rxjs-compat": "^6.5.3",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.29"
},
"devDependencies": {
"#ionic/app-scripts": "3.2.2",
"typescript": "3.2.2"
},
I got an error blow, please find it:
[20:15:04] typescript: ...e_m_pwd_app/e_i/node_modules/#firebase/database/dist/src/api/Database.d.ts, line: 44
An accessor cannot be declared in an ambient context.
L43: * We throw a exception if the url is not in the same domain as the
L44: * current repo.
L45: * #param {string} url
[20:15:04] typescript: ...m_pwd_app/e_i/node_modules/#firebase/database/dist/src/api/DataSnapshot.d.ts, line: 88
An accessor cannot be declared in an ambient context.
[20:15:04] typescript: ...m_pwd_app/e_i/node_modules/#firebase/database/dist/src/api/DataSnapshot.d.ts, line: 98
An accessor cannot be declared in an ambient context.
[20:15:04] typescript: ...nd/e_p/e_i/node_modules/#firebase/database/dist/src/api/Query.d.ts, line: 36
An accessor cannot be declared in an ambient context.
L36: * Validates that no other order by call has been made
L37: * #param {!string} fnName
[20:15:04] typescript: ...nd/e_p/e_i/node_modules/#firebase/database/dist/src/api/Query.d.ts, line: 37
An accessor cannot be declared in an ambient context.
L36: * Validates that no other order by call has been made
L37: * #param {!string} fnName
L38: * #private
i am working with firebase database with ionic framework. when i trying to connect with firebase i am getting above mentioned error in ionic framework,
please give me a solution for this issue.
please check the keyname firebase as well as your code (fnName). please share your code

Meteor not running showing issue with node-fiber

I have a meteor project. It was running two days before. Now I am getting the following error.
## There is an issue with `node-fibers` ##
W20181017-19:00:42.197(7)? (STDERR)
D:\Work\store\node_modules\fibers\bin\win32-x64-57\fibers.node`
is missing.
(STDERR) Try running this to fix the issue:
C:\Users\mritu\AppData\Local\.met
eor\packages\meteor-tool\1.6.0_1\mt-os.windows.x86_64\dev_bundle\bin\node.exe
D:\Work\store\node_modules
\fibers/build
W20181017-19:00:42.199(7)? (STDERR)
D:\Work\store\node_modules\fibers\fibers.js:20
W20181017-19:00:42.199(7)? (STDERR) throw new Error('Missing binary. See
message above.');
W20181017-19:00:42.199(7)? (STDERR) ^
W20181017-19:00:42.199(7)? (STDERR)
W20181017-19:00:42.200(7)? (STDERR) Error: Missing binary. See message above.
W20181017-19:00:42.200(7)? (STDERR) at Object.<anonymous>
(D:\Work\store\node_modules\fibers\fibers.
js:20:8)
W20181017-19:00:42.200(7)? (STDERR) at Module._compile (module.js:635:30)
W20181017-19:00:42.201(7)? (STDERR) at Object.Module._extensions..js
My package.json is
{
"name": "frontstore",
"private": true,
"dependencies": {
"babel-runtime": "^6.23.0",
"bcrypt": "^1.0.2",
"fibers": "^1.0.15",
"jquery": "^2.2.4",
"lodash": "^4.17.3",
"mailchimp-api-v3": "^1.7.0",
"md5": "^2.2.1",
"meteor-node-stubs": "~0.2.0",
"meteor-react-autoform": "^0.3.0",
"mobile-detect": "^1.3.5",
"moment": "*",
"moment-range": "^2.2.0",
"omise": "^0.5.3",
"prop-types": "^15.5.8",
"react": "^15.3.1",
"react-addons-css-transition-group": "^15.4.2",
"react-addons-pure-render-mixin": "^15.3.2",
"react-bootstrap": "^0.30.3",
"react-burger-menu": "^1.10.9",
"react-date-range": "github:bchurunway/datepicker",
"react-day-picker": "^2.5.0",
"react-dom": "^15.3.1",
"react-helmet": "^5.2.0",
"react-html-parser": "^1.0.3",
"react-infinite-scroll-component": "^2.2.2",
"react-lazy-load": "^3.0.11",
"react-lazyload": "^2.2.7",
"react-loading": "0.0.9",
"react-mounter": "github:bchurunway/react-mounter",
"react-notification-system": "^0.2.11",
"react-number-format": "^1.0.0",
"react-player": "^0.14.3",
"react-radio-group": "^3.0.1",
"react-select": "^2.0.0",
"react-share": "^1.12.1",
"react-slick": "0.14.5",
"react-stars": "^2.2.5",
"react-structured-data": "^0.0.7",
"react-tooltip": "^3.2.7",
"simpl-schema": "^1.4.1",
"twix": "^1.2.1"
},
"devDependencies": {
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-preset-stage-3": "^6.22.0"
}
}
My meteor version is 1.6.1. I have tried many ways like deleting node_modules and install it again, delete local folder from meteor and regain it again using meteor command. But nothing works.

Nativescript Firebase plugin - “cannot read property of null” after upgrade to NS 3.4.0

My angular - Nativescript project uses the Nativescript-Firebase-Plugin. It works perfectly well in Nativescript 3.3
I upgraded my project to Nativescript 3.4. After upgrading the project, I am facing a major issue with all firebase queries.
**JS: Error in firebase.query: TypeError: Cannot read property 'child' of null**
JS: NO QUESTIONS FOR THIS USER
JS: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined
JS: TypeError: Cannot read property 'length' of undefined
JS: at file:///data/data/org.nativescript.qbank/files/app/feed/alphaCreate.component.js:55:23
JS: at SafeSubscriber.schedulerFn [as _next] (file:///data/data/org.nativescript.qbank/files/app/tns_modules/#angular/core/bundles/core.umd.js:3870:36)
JS: at SafeSubscriber.__tryOrUnsub (file:///data/data/org.nativescript.qbank/files/app/tns_modules/rxjs/Subscriber.js:238:16)
JS: at SafeSubscriber.next (file:///data/data/org.nativescript.qbank/files/app/tns_modules/rxjs/Subscriber.js:185:22)
JS: at Subscriber._next (file:///data/data/org.nativescript.qbank/files/app/tns_modules/rxjs/Subscriber.js:125:26)
JS: at Subscriber.next (file:///data/data/org.nativescript.qbank/files/app/tns_modules/rxjs/Subscriber.js:89:18)
JS: at EventEmitter.Subject.next (file:///data/data/org.nativescript.qbank/files/app/tns_modules/rxjs/Subject.js:55:25)
JS: at EventEmitter.emit (file:///data/data/org.nativescript.qbank/files/app/tns_modules/#angular/core/bundles/core.umd.js:3844:76)
JS: at file:///data/data/org.nativescript.qbank/files/app/services/my-questions.service.js:51:42
JS: at ZoneDelegate.invoke (file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:365:26)
JS: at Object.onInvoke (file:///data/data/org.nativescript.qbank/files/app/tns_modules/#angular/core/bundles/core.umd.js:4156:37)
JS: at ZoneDelegate.invoke (file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:364:32)
JS: at Zone.run (file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:125:43)
JS: at file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:760:57
JS: at ZoneDelegate.invokeTask (file:///data/data/org.nativescript.qbank/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:398:31)
I tried to resolve it by
a. upgrading the native script firebase plugin: 5.0.5
b. upgrading all the dependenices of the project
But the issue is still occurring. This is a big blocker, and Please suggest what I can do to fix this.
My package json is as below:
{
"android": {
"markingMode": "none"
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"readme": "NativeScript Application",
"repository": "<fill-your-repository-here>",
"nativescript": {
"id": "org.nativescript.qbank",
"tns-ios": {
"version": "3.4.0"
},
"tns-android": {
"version": "3.4.0"
}
},
"dependencies": {
"#angular/animations": "~5.0.0",
"#angular/common": "~5.0.0",
"#angular/compiler": "~5.0.0",
"#angular/core": "~5.0.0",
"#angular/forms": "~5.0.0",
"#angular/http": "~5.0.0",
"#angular/platform-browser": "~5.0.0",
"#angular/platform-browser-dynamic": "~5.0.0",
"#angular/router": "~5.0.0",
"nativescript-algolia": "0.0.4",
"nativescript-angular": "~5.0.0",
"nativescript-camera": "^3.1.4",
"nativescript-email": "^1.5.1",
"nativescript-fancyalert": "^1.1.2",
"nativescript-filter-select": "^1.2.1",
"nativescript-geolocation": "^3.0.0",
"nativescript-gif": "^1.0.9",
"nativescript-imagepicker": "^4.0.1",
"nativescript-iqkeyboardmanager": "^1.1.0",
"nativescript-loading-indicator": "^2.3.2",
"nativescript-plugin-firebase": "^5.0.5",
"nativescript-pro-ui": "^3.3.0",
"nativescript-theme-core": "~1.0.4",
"nativescript-toast": "^1.4.5",
"nativescript-web-image-cache": "^4.2.2",
"reflect-metadata": "~0.1.8",
"rxjs": "^5.5.0",
"tns-core-modules": "^3.4.0"
},
"devDependencies": {
"babel-traverse": "6.26.0",
"babel-types": "6.26.0",
"babylon": "6.18.0",
"codelyzer": "~4.0.2",
"es6-promise-loader": "^1.0.2",
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.6.0",
"tslint": "^5.1.0",
"typescript": "~2.4.2",
"zone.js": "^0.8.4"
}
}
The problem was that firebase was not initialising. I solved this by putting firebase init in a timeout.

Resources