Barcode Scanner was giving a run time error

I imported import { BarcodeScanner } from ‘@ionic-native/barcode-scanner/ngx’; and I installed barcode scanner ngx. While it was scanning in another project, it does not work in a bigger project.

ERROR TypeError: Object(…) is not a function at BarcodeScanner.scan (index.js:31) at HomePage.webpackJsonp.31.HomePage.scanCode (home.ts:64) at Object.eval [as handleEvent] (HomePage.html:63) at handleEvent (core.js:13547) at callWithDebugContext (core.js:15056) at Object.debugHandleEvent [as handleEvent] (core.js:14643) at dispatchEvent (core.js:9962) at core.js:10587 at HTMLButtonElement. (platform-browser.js:2628) at t.invokeTask (polyfills.js:3)

here is my ionic info:

Ionic CLI : 5.2.3 (C:\Users\Dogaç\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.4


Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 1.2.1, (and 8 other plugins)


cordova-res : not installed
native-run : 0.2.8


NodeJS : v10.16.0 (C:\Program Files\nodejs\node.exe)
npm : 6.9.0
OS : Windows 10

home.html content: <button ion-button full icon-left (click)=“scanCode()” expand=“full” size=“large” color=“dark”>
Scan barcode


this.BarcodeScanner.scan().then(data => {
// this is called when a barcode is found
this.scannedCode = data.text

Every time I’ve seen this in a similar context it’s been caused by a mishmash of versions of various Ionic-Native things. Look in your package.json for things related to ionic-native and align all their major versions.

1 Like

I updated all of Ionic-Native things in package.json however, I got another error.
Here is the error

compiler.js:485 Uncaught Error: Can't resolve all parameters for MyApp: ([object Object], ?, ?, ?, [object Object], [object Object]).
    at syntaxError (compiler.js:485)
    at CompileMetadataResolver._getDependenciesMetadata (compiler.js:15700)
    at CompileMetadataResolver._getTypeMetadata (compiler.js:15535)
    at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:15020)
    at CompileMetadataResolver._getEntryComponentMetadata (compiler.js:15848)
    at compiler.js:15829
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver._getEntryComponentsFromProvider (compiler.js:15828)
    at compiler.js:15783
    at Array.forEach (<anonymous>)

Look at the parameters of the MyApp constructor in the order they are defined. The ones that match up with the ? are the problem. Perhaps they have not been declared as providers in the app module.