Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunTime Error: Cannot read property 'split' of undefined #992

Closed
wshaheer opened this issue Jan 21, 2017 · 10 comments · Fixed by #998
Closed

RunTime Error: Cannot read property 'split' of undefined #992

wshaheer opened this issue Jan 21, 2017 · 10 comments · Fixed by #998

Comments

@wshaheer
Copy link

After updating to v2.3.0, running ionic serve causes this error. Tried this on a fresh blank project

@basvdijk
Copy link

Got the same problem, reverting to 2.2.16 made my build work again.

@chron0
Copy link

chron0 commented Jan 21, 2017

Ditto:

TypeError: Cannot read property 'split' of undefined
    at get (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/util.js:3:32)
    at getPlugin (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/plugins/plugin.js:23:85)
    at CordovaProperty (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/plugins/plugin.js:431:26)
    at __decorate (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/plugins/apprate.js:6:110)
    at eval (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/plugins/apprate.js:44:5)
    at eval (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/plugins/apprate.js:60:2)
    at Object.<anonymous> (http://localhost:8100/build/main.js:3039:1)
    at __webpack_require__ (http://localhost:8100/build/main.js:20:30)
    at eval (/home/chrono/src/governess/client/node_modules/ionic-native/dist/esm/index.js:6:75)
    at Object.<anonymous> (http://localhost:8100/build/main.js:2997:1)
Ionic Framework: 2.0.0-rc.5
Ionic Native: 2.3.0
Ionic App Scripts: 1.0.0
Angular Core: 2.2.1
Angular Compiler CLI: 2.2.1
Node: 4.6.1
OS Platform: Linux 4.8
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36

@fmoessle
Copy link

Same problem over here, but i did not get in working with 2.2.16 or 2.2.17

@chron0
Copy link

chron0 commented Jan 21, 2017

@fmoessle: 2.2.16 is working correctly here, sure that your other ionic deps and ionic itself are up-to-date?

@fmoessle
Copy link

You are right! Thanks, it works :)

@guillenotfound
Copy link
Contributor

Seems to be caused by 67adb23, tested master + cherry-pick of src/plugins/plugin.ts from 9541009 and the issue disappears.

@almothafar
Copy link

almothafar commented Jan 22, 2017

Got the same issue, I after upgrading my exist project from 2.2.16 to 2.3.0 (and tried 2.2.17 and seems it has the same issue):

Uncaught TypeError: Cannot read property 'split' of undefined
    at Object.get (ionic.native.js:18012)
    at Object.exports.getPlugin (ionic.native.js:14412)
    at CordovaProperty (ionic.native.js:14824)
    at __decorate (ionic.native.js:1018)
    at ionic.native.js:1056
    at Object.8../plugin (ionic.native.js:1072)
    at s (ionic.native.js:1)
    at ionic.native.js:1
    at Object.1../ng1 (ionic.native.js:12)
    at s (ionic.native.js:1)
    at e (ionic.native.js:1)
    at ionic.native.js:1

ionic-cli 2.2.1
Ionic Framework: 1.3.2

@peterkelly
Copy link
Contributor

This does indeed appear to be caused by 67adb23, which was a fix to #954. This change did two things, only the second of which was necessary for the bug it was intended to fix:

  1. Replace multiple calls to getPlugin(target.pluginRef) with a single call that happens at the top of the function.

  2. Return null instead of {} when the exists() call returns false.

The exception is occurring because of change 1. The CordovaProperty decorator is attempting to access target.pluginRef, which is not yet defined. It is the Plugin decorator which defines this property, but this is executed only after the CordovaProperty decorator, which in turn is executed only after the class in which the property is defined is called.

I believe the solution is to move the calls to getPlugin back to where they were before; this will mean the CordovaProperty decorator will be executed before the getPlugin calls, and thus target.pluginRef will at that point be defined.

peterkelly added a commit to peterkelly/ionic-native that referenced this issue Jan 22, 2017
This reverts part of commit 67adb23, which moved the call to getPlugin()
from within CordovaProperty() to a point where it was called too early.

When the CordovaProperty decorator is called on a property, the class
containing that call has not yet had its Plugin decorator called. Only
when the latter happens does pluginRef get set. Thus, attempting to
access pluginRef within CordovaProperty at the time of the call will
give undefined, and attemping to call getPlugin with an undefined value
will throw an exception:

    Runtime Error
    Cannot read property 'split' of undefined

    TypeError: Cannot read property 'split' of undefined
        at get
        at getPlugin
        at CordovaProperty
        at __decorate
        ...

The above message can be seen in the browser after running the 'ionic
serve' command.

This commit moves the getPlugin call back to the getters and setters
established by CordovaProperty, which are only called *after* the Plugin
decorator has finished executing.

closes danielsogl#992
ihadeed pushed a commit that referenced this issue Jan 22, 2017
This reverts part of commit 67adb23, which moved the call to getPlugin()
from within CordovaProperty() to a point where it was called too early.

When the CordovaProperty decorator is called on a property, the class
containing that call has not yet had its Plugin decorator called. Only
when the latter happens does pluginRef get set. Thus, attempting to
access pluginRef within CordovaProperty at the time of the call will
give undefined, and attemping to call getPlugin with an undefined value
will throw an exception:

    Runtime Error
    Cannot read property 'split' of undefined

    TypeError: Cannot read property 'split' of undefined
        at get
        at getPlugin
        at CordovaProperty
        at __decorate
        ...

The above message can be seen in the browser after running the 'ionic
serve' command.

This commit moves the getPlugin call back to the getters and setters
established by CordovaProperty, which are only called *after* the Plugin
decorator has finished executing.

closes #992
@ajeethhacki
Copy link

Same problem over here, but i did not get in working with 2.2.16 or 2.2.17

buddy how to revert this

@ajeethhacki
Copy link

Please help me ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants