dapriett / nativescript-google-maps-sdk

Cross Platform Google Maps SDK for Nativescript
MIT License
244 stars 164 forks source link

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

Open liamcharmer opened 3 years ago

liamcharmer commented 3 years ago

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

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

ebiscardi commented 3 years ago

Same error with NativeScript 7.0.8 with typescript (NativeScript Core)

mouadhkaabachi commented 3 years ago

Same error

ptl-miguel commented 3 years ago

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

ptl-miguel commented 3 years ago

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<…>

ptl-miguel commented 3 years ago

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.

benco8186 commented 3 years ago

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 :(

mouadhkaabachi commented 3 years ago

@benco8186 try this: 1) tns install babel 2) put this in .babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "esmodules": true
        },
        "include": [
          "transform-classes"
        ]
      }
    ]
  ]
}
benco8186 commented 3 years ago

@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 commented 3 years ago

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/

liamcharmer commented 3 years ago

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

benco8186 commented 3 years ago

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

mouadhkaabachi commented 3 years ago

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.

hypery2k commented 3 years ago

getting the same error

hypery2k commented 3 years ago

see #420

benco8186 commented 3 years ago

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

kefahB commented 3 years ago

@hypery2k cool staff 👍

the infoWindowTemplate does not showing on !

funder7 commented 3 years ago

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

kefahB commented 3 years ago

@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.

funder7 commented 3 years ago

.. 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)

kefahB commented 3 years ago

It work as expected with NS6.3

RibuRoyson commented 3 years ago

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...!!!

jlafitte commented 3 years ago

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.

mouadhkaabachi commented 3 years ago

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

kefahB commented 3 years ago

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",
manishgautam12 commented 1 year ago

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

kefahB commented 1 year ago

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