Happening now | Office Hours: Customizing Your Theme With Moeed | Ask your questions now!
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: TypeError: t.split is not a function

Solved

TypeError: t.split is not a function

Indinuity
Shopify Partner
41 1 2

I am currently working on converting our EASDK integration to App-Bridge and I am hitting road-block after road-block.

 

This basis example is throwing a javascript error

 

 

<script src="https://unpkg.com/@shopify/app-bridge@1"></script>
<script>
  var AppBridge = window['app-bridge'];

  var app = AppBridge.createApp({
    apiKey: 'my_api_key',
    shopOrigin: 'example.myshopify.com'
  });

  try {
      console.log('Fetching State');
      app.getState(function() {
          console.log('Got State');
      });
      
  } catch (e) {
	  console.log(e);
  }
</script>

 

 

This results in 

 

app-bridge@1:1 Uncaught (in promise) TypeError: t.split is not a function
at app-bridge@1:1
(anonymous) @ app-bridge@1:1
Promise.then (async)
getState @ app-bridge@1:1
(anonymous) @ {my endpoint}

This is extremely frustrating.. can anyone suggest what can be done.. this is a basic browser example.. brutal. 

 

Reward yourself and your Customers.
Accepted Solution (1)
Indinuity
Shopify Partner
41 1 2

This is an accepted solution.

Looks like the call to getState is incorrect and should be 

 

  app.getState().then(function(data) {
      console.log(data);
  });

 

Works in the Admin now, but doesn't work on POS..  which is 

 

  app.getState('pos').then(function(data) {
      console.log(data);
  });

 

 

Reward yourself and your Customers.

View solution in original post

Replies 4 (4)

Indinuity
Shopify Partner
41 1 2

Note the exact same error occurs when using app-bridge@2

 

Testing in Chrome browser, the most recent version. 

Reward yourself and your Customers.
Indinuity
Shopify Partner
41 1 2

Switched to dev version

 

<script src="https://unpkg.com/@shopify/app-bridge@1/umd/index.development.js"></script>

 

The error is now

 

Uncaught (in promise) TypeError: query.split is not a function
at index.development.js:2943
(anonymous) @ index.development.js:2943
Promise.then (async)
getState @ index.development.js:2941
(anonymous) @ {my endpoint}

Reward yourself and your Customers.
Indinuity
Shopify Partner
41 1 2

@Shopify the code here doesn't make sense.. 

            getState: function (query) {
                return new Promise(function (resolve) {
                    getStateListeners.push(resolve);
                    dispatcher(types_1.MessageType.GetState);
                }).then(function (state) {
                    if (query) {
                        return query.split('.').reduce(function (value, key) {
                            if (typeof state !== 'object' || Array.isArray(state)) {
                                return undefined;
                            }
                            value = state[key];
                            state = value;
                            return value;
                        }, undefined);
                    }
                    return state;
                });
            },

 

the getState method takes a query argument - which is a function according to the docs - https://shopify.dev/apps/tools/app-bridge/methods#app-object-methods

 

So why then are you calling 

 

return query.split('.').

 

on something that is supposed to be a function??

 

 

Reward yourself and your Customers.
Indinuity
Shopify Partner
41 1 2

This is an accepted solution.

Looks like the call to getState is incorrect and should be 

 

  app.getState().then(function(data) {
      console.log(data);
  });

 

Works in the Admin now, but doesn't work on POS..  which is 

 

  app.getState('pos').then(function(data) {
      console.log(data);
  });

 

 

Reward yourself and your Customers.