nativescript-google-maps-sdk icon indicating copy to clipboard operation
nativescript-google-maps-sdk copied to clipboard

TypeError: Class constructor View cannot be invoked without 'new'

Open liamcharmer opened this issue 3 years ago • 26 comments

TypeError: Class constructor View cannot be invoked without 'new'

NativeScript 7 with Vue.js when trying to create the map.

liamcharmer avatar Sep 22 '20 15:09 liamcharmer

Same error with NativeScript 7.0.8 with typescript (NativeScript Core)

ebiscardi avatar Sep 23 '20 12:09 ebiscardi

Same error

mouadhkaabachi avatar Sep 23 '20 19:09 mouadhkaabachi

same error w/ Nativescript 7.0.7 with JS (NativeScript Vue)

poorly-taught avatar Sep 23 '20 20:09 poorly-taught

I managed to invoke this error by trying to create an instance outside of the registerElement CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Uncaught TypeError: Class constructor View cannot be invoked without 'new' at MapViewBase(file: node_modules/nativescript-google-maps-sdk/map-view-common.js:128:46) at MapView(file: node_modules/nativescript-google-maps-sdk/map-view.ios.js:240:27) at (file:///app/bundle.js:887:12) at ./main.js(file:///app/bundle.js:907:30) at __webpack_require__(file: src/webpack/bootstrap:816:0) at checkDeferredModules(file: src/webpack/bootstrap:43:0) at webpackJsonpCallback(file: src/webpack/bootstrap:30:0) at (file:///app/bundle.js:2:57) at require(:1:137) ', reason: '(null)' *** First throw call stack: ( 0 CoreFoundation 0x00007fff2043a126 __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007fff20177f78 objc_exception_throw + 48 2 NativeScript 0x000000010d7f62b4 _ZN3tns21NativeScriptException15OnUncaughtErrorEN2v85LocalINS1_7MessageEEENS2_INS1_5ValueEEE + 882 3 NativeScript 0x000000010dc23668 _ZN2v88internal14Me<…>

poorly-taught avatar Sep 23 '20 21:09 poorly-taught

So my issue turned out be the handling of the plugin by babel

presets: [ [ '@babel/preset-env', { targets: { esmodules: true }, ----> include: ["transform-classes"] } ] ],

the inclusion of "include":"[transform-classes"] solved it for me, I arrived to this answer through this https://stackoverflow.com/questions/36577683/babel-error-class-constructor-foo-cannot-be-invoked-without-new answer. I hope this helps someone.

poorly-taught avatar Sep 23 '20 22:09 poorly-taught

So my issue turned out be the handling of the plugin by babel

presets: [ [ '@babel/preset-env', { targets: { esmodules: true }, ----> include: ["transform-classes"] } ] ],

the inclusion of "include":"[transform-classes"] solved it for me, I arrived to this answer through this https://stackoverflow.com/questions/36577683/babel-error-class-constructor-foo-cannot-be-invoked-without-new answer. I hope this helps someone.

Hi, could you show your code please? I include a .babelrc file with your presets but this solution doesn't work for me :(

benco8186 avatar Sep 24 '20 19:09 benco8186

@benco8186 try this:

  1. tns install babel
  2. put this in .babelrc
{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "esmodules": true
        },
        "include": [
          "transform-classes"
        ]
      }
    ]
  ]
}

mouadhkaabachi avatar Sep 24 '20 21:09 mouadhkaabachi

@benco8186 try this:

  1. tns install babel
  2. put this in .babelrc
{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "esmodules": true
        },
        "include": [
          "transform-classes"
        ]
      }
    ]
  ]
}

Thank you, but it still doesn't work, may be it's because i'm using angular and not vue, also i'm not on nativescript 7, i use nativescript 6.5.3

benco8186 avatar Sep 24 '20 23:09 benco8186

I have created a fork and updated nativescript dependencies and typescript compiler version, if you compile the files and replace in the node module by these (map-view-common.js,map-view.android.js,map-view.ios.js,map-view.d.js),it works the fork url : https://github.com/benco8186/nativescript-google-maps-sdk/

benco8186 avatar Sep 28 '20 15:09 benco8186

I have created a fork and updated nativescript dependencies and typescript compiler version, if you compile the files and replace in the node module by these (map-view-common.js,map-view.android.js,map-view.ios.js,map-view.d.js),it works the fork url : https://github.com/benco8186/nativescript-google-maps-sdk/

Tried but wasn't able to get this achieved

liamcharmer avatar Oct 01 '20 11:10 liamcharmer

I have created a fork and updated nativescript dependencies and typescript compiler version, if you compile the files and replace in the node module by these (map-view-common.js,map-view.android.js,map-view.ios.js,map-view.d.js),it works the fork url : https://github.com/benco8186/nativescript-google-maps-sdk/

Tried but wasn't able to get this achieved

Clone my fork, in the src folder open a terminal and run npm install, then tsc, don't worry about error informations. After that copy the .js files and in your project, in the original dependency nativescript maps sdk (in node_module), paste these files (replace the Originals). Normally that will work

benco8186 avatar Oct 01 '20 13:10 benco8186

I have created a fork and updated nativescript dependencies and typescript compiler version, if you compile the files and replace in the node module by these (map-view-common.js,map-view.android.js,map-view.ios.js,map-view.d.js),it works the fork url : https://github.com/benco8186/nativescript-google-maps-sdk/

Tried but wasn't able to get this achieved

Clone my fork, in the src folder open a terminal and run npm install, then tsc, don't worry about error informations. After that copy the .js files and in your project, in the original dependency nativescript maps sdk (in node_module), paste these files (replace the Originals). Normally that will work

I tried this and now I got new error : Error: This value is not a native object.

mouadhkaabachi avatar Oct 03 '20 19:10 mouadhkaabachi

getting the same error

hypery2k avatar Oct 07 '20 08:10 hypery2k

see #420

hypery2k avatar Oct 07 '20 12:10 hypery2k

sorry, don't replace map-view.d.ts by a js file but by the ts file I attach a zip file with the files I used maps.zip

benco8186 avatar Oct 07 '20 14:10 benco8186

@hypery2k cool staff 👍

the infoWindowTemplate does not showing on !

kefahB avatar Oct 07 '20 16:10 kefahB

hi @kefahB, when the infoWindow is not showing? thx

funder7 avatar Oct 08 '20 19:10 funder7

@funder7 .. this happen when I click on the marker .. I've did some debugs, it seems the infowindow does not exist at all on the plugin side.

kefahB avatar Oct 08 '20 21:10 kefahB

.. this happen when I click on the marker .. I've did some debugs, it seems the infowindow does not exist at all on the plugin side.

Okay! Does it happen with the stable version of the plugin and nativescript 7+ or with the plugin version of #420? (nativescript 7 compatibility PR)

funder7 avatar Oct 10 '20 21:10 funder7

It work as expected with NS6.3

kefahB avatar Oct 10 '20 21:10 kefahB

sorry, don't replace map-view.d.ts by a js file but by the ts file I attach a zip file with the files I used maps.zip

@benco8186 got this worked..but cameraChanged function not working after i tired this...!!!

RibuRoyson avatar Oct 13 '20 10:10 RibuRoyson

I could not get this working either with NS7. But as documented here a bit, I was having problems still trying to use the old CLI with ios. So I'm basically using NS7 cli with my NS6 project, and it seems to work I just have to use --force. This will probably hold me over for now, but would really like to get it working with NS7 fully at some point.

jlafitte avatar Oct 14 '20 14:10 jlafitte

sorry, don't replace map-view.d.ts by a js file but by the ts file I attach a zip file with the files I used maps.zip

@benco8186 got this worked..but cameraChanged function not working after i tired this...!!!

@benco8186 same issue

mouadhkaabachi avatar Oct 17 '20 17:10 mouadhkaabachi

Hi,

to resolve this issue you should declare NativeClass() on MapViewDelegateImpl and IndoorDisplayDelegateImpl then you add ts-patch at your package.json (dev), then add the flowing to your tsconfig.json

"plugins": [{
            "transform": "@nativescript/webpack/transformers/ns-transform-native-classes",
            "type": "raw"
        }]

and edit package.json at the script key like this :

"build": "npm run clean && ts-patch install && tsc",

kefahB avatar Nov 06 '20 10:11 kefahB

same error...anyone handle this problem ...please describe breafly

manishgautam12 avatar Nov 05 '22 19:11 manishgautam12

Hi every one, this repo isn’t maintained frequently, try This plugin

kefahB avatar Nov 05 '22 21:11 kefahB