'Cannot read property 'browser' of undefined' in Nativescript + Angular using Apache thrift

Multi tool use
Multi tool use












2














I`m trying to use Apache Thrift with my Angular & Nativescript project, but by the 'tns preview --bundle' or any another tns command i get



TypeError: Cannot read property 'browser' of undefined
File: "<unknown>, line: 1, column: 265


Apache Thrift v. 0.11.0 / 1.0.0dev, Angular v. 7.1.0, Nativescript v. 5.1.0



In platforms/android/app/src/main/assets/app/vendor.js i can see:



/* istanbul ignore next */
if (undefined.browser) {
defaultEncoding = 'utf-8'
} else {
var pVersionMajor = parseInt(undefined.version.split('.')[0].slice(1), 10)


When i expected something like global.process.browser, than i can find at another peaces of vendor.js.
And in another peaces i can see something like undefined.nextTick(...) etc.
I know it is some kind of Babel problem, but i have no idea how to fix it.



I use thrift --gen js:node script to generate my thrift files (it doesn't make sense in error). Without them all works cool, but then i'm trying to execute any thrift-generated file/any module from thrift, i get an exception above.
my_component.ts



import { Component, OnInit } from '@angular/core';
import { TJSONProtocol } from 'thrift'; // or anything else

@Component({...});

export class MyComponent implements OnInit {
ngOnInit () {
// console.log(TJSONProtocol); // Uncomment this string to get an exception.
}
constructor() {...};
}


There is any problems provided by ng serve.
I hope here is any way to fix this mistake and make thrift compatible with nativescript or any another way to use thrift with nativescript.










share|improve this question





























    2














    I`m trying to use Apache Thrift with my Angular & Nativescript project, but by the 'tns preview --bundle' or any another tns command i get



    TypeError: Cannot read property 'browser' of undefined
    File: "<unknown>, line: 1, column: 265


    Apache Thrift v. 0.11.0 / 1.0.0dev, Angular v. 7.1.0, Nativescript v. 5.1.0



    In platforms/android/app/src/main/assets/app/vendor.js i can see:



    /* istanbul ignore next */
    if (undefined.browser) {
    defaultEncoding = 'utf-8'
    } else {
    var pVersionMajor = parseInt(undefined.version.split('.')[0].slice(1), 10)


    When i expected something like global.process.browser, than i can find at another peaces of vendor.js.
    And in another peaces i can see something like undefined.nextTick(...) etc.
    I know it is some kind of Babel problem, but i have no idea how to fix it.



    I use thrift --gen js:node script to generate my thrift files (it doesn't make sense in error). Without them all works cool, but then i'm trying to execute any thrift-generated file/any module from thrift, i get an exception above.
    my_component.ts



    import { Component, OnInit } from '@angular/core';
    import { TJSONProtocol } from 'thrift'; // or anything else

    @Component({...});

    export class MyComponent implements OnInit {
    ngOnInit () {
    // console.log(TJSONProtocol); // Uncomment this string to get an exception.
    }
    constructor() {...};
    }


    There is any problems provided by ng serve.
    I hope here is any way to fix this mistake and make thrift compatible with nativescript or any another way to use thrift with nativescript.










    share|improve this question



























      2












      2








      2


      1





      I`m trying to use Apache Thrift with my Angular & Nativescript project, but by the 'tns preview --bundle' or any another tns command i get



      TypeError: Cannot read property 'browser' of undefined
      File: "<unknown>, line: 1, column: 265


      Apache Thrift v. 0.11.0 / 1.0.0dev, Angular v. 7.1.0, Nativescript v. 5.1.0



      In platforms/android/app/src/main/assets/app/vendor.js i can see:



      /* istanbul ignore next */
      if (undefined.browser) {
      defaultEncoding = 'utf-8'
      } else {
      var pVersionMajor = parseInt(undefined.version.split('.')[0].slice(1), 10)


      When i expected something like global.process.browser, than i can find at another peaces of vendor.js.
      And in another peaces i can see something like undefined.nextTick(...) etc.
      I know it is some kind of Babel problem, but i have no idea how to fix it.



      I use thrift --gen js:node script to generate my thrift files (it doesn't make sense in error). Without them all works cool, but then i'm trying to execute any thrift-generated file/any module from thrift, i get an exception above.
      my_component.ts



      import { Component, OnInit } from '@angular/core';
      import { TJSONProtocol } from 'thrift'; // or anything else

      @Component({...});

      export class MyComponent implements OnInit {
      ngOnInit () {
      // console.log(TJSONProtocol); // Uncomment this string to get an exception.
      }
      constructor() {...};
      }


      There is any problems provided by ng serve.
      I hope here is any way to fix this mistake and make thrift compatible with nativescript or any another way to use thrift with nativescript.










      share|improve this question















      I`m trying to use Apache Thrift with my Angular & Nativescript project, but by the 'tns preview --bundle' or any another tns command i get



      TypeError: Cannot read property 'browser' of undefined
      File: "<unknown>, line: 1, column: 265


      Apache Thrift v. 0.11.0 / 1.0.0dev, Angular v. 7.1.0, Nativescript v. 5.1.0



      In platforms/android/app/src/main/assets/app/vendor.js i can see:



      /* istanbul ignore next */
      if (undefined.browser) {
      defaultEncoding = 'utf-8'
      } else {
      var pVersionMajor = parseInt(undefined.version.split('.')[0].slice(1), 10)


      When i expected something like global.process.browser, than i can find at another peaces of vendor.js.
      And in another peaces i can see something like undefined.nextTick(...) etc.
      I know it is some kind of Babel problem, but i have no idea how to fix it.



      I use thrift --gen js:node script to generate my thrift files (it doesn't make sense in error). Without them all works cool, but then i'm trying to execute any thrift-generated file/any module from thrift, i get an exception above.
      my_component.ts



      import { Component, OnInit } from '@angular/core';
      import { TJSONProtocol } from 'thrift'; // or anything else

      @Component({...});

      export class MyComponent implements OnInit {
      ngOnInit () {
      // console.log(TJSONProtocol); // Uncomment this string to get an exception.
      }
      constructor() {...};
      }


      There is any problems provided by ng serve.
      I hope here is any way to fix this mistake and make thrift compatible with nativescript or any another way to use thrift with nativescript.







      angular webpack nativescript babel thrift






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 27 at 13:41

























      asked Dec 27 at 13:31









      Serega Tihovsky

      265




      265
























          2 Answers
          2






          active

          oldest

          votes


















          1














          When an application uses browser data (document, window, etc), you need to make sure that this data is accessed only when the application is running in the browser itself, which is not the case in nodejs.



          To do this, place the code snippet you need to use within a check like:



          if (typeof window !== 'undefined') {
          // here runs your code...
          console.log(TJSONProtocol);
          }


          See: https://angular.io/guide/universal#working-around-the-browser-apis






          share|improve this answer























          • Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
            – Serega Tihovsky
            Dec 27 at 14:08



















          1














          The problem was in default webpack.config.js, provided by Nativescript. At:



          plugins: [
          // Define useful constants like TNS_WEBPACK
          new webpack.DefinePlugin({
          "global.TNS_WEBPACK": "true",
          "process": undefined,
          })


          You need to remove line "process": undefined.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945922%2fcannot-read-property-browser-of-undefined-in-nativescript-angular-using-ap%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            When an application uses browser data (document, window, etc), you need to make sure that this data is accessed only when the application is running in the browser itself, which is not the case in nodejs.



            To do this, place the code snippet you need to use within a check like:



            if (typeof window !== 'undefined') {
            // here runs your code...
            console.log(TJSONProtocol);
            }


            See: https://angular.io/guide/universal#working-around-the-browser-apis






            share|improve this answer























            • Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
              – Serega Tihovsky
              Dec 27 at 14:08
















            1














            When an application uses browser data (document, window, etc), you need to make sure that this data is accessed only when the application is running in the browser itself, which is not the case in nodejs.



            To do this, place the code snippet you need to use within a check like:



            if (typeof window !== 'undefined') {
            // here runs your code...
            console.log(TJSONProtocol);
            }


            See: https://angular.io/guide/universal#working-around-the-browser-apis






            share|improve this answer























            • Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
              – Serega Tihovsky
              Dec 27 at 14:08














            1












            1








            1






            When an application uses browser data (document, window, etc), you need to make sure that this data is accessed only when the application is running in the browser itself, which is not the case in nodejs.



            To do this, place the code snippet you need to use within a check like:



            if (typeof window !== 'undefined') {
            // here runs your code...
            console.log(TJSONProtocol);
            }


            See: https://angular.io/guide/universal#working-around-the-browser-apis






            share|improve this answer














            When an application uses browser data (document, window, etc), you need to make sure that this data is accessed only when the application is running in the browser itself, which is not the case in nodejs.



            To do this, place the code snippet you need to use within a check like:



            if (typeof window !== 'undefined') {
            // here runs your code...
            console.log(TJSONProtocol);
            }


            See: https://angular.io/guide/universal#working-around-the-browser-apis







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 27 at 13:47

























            answered Dec 27 at 13:36









            Caio Ladislau

            474521




            474521












            • Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
              – Serega Tihovsky
              Dec 27 at 14:08


















            • Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
              – Serega Tihovsky
              Dec 27 at 14:08
















            Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
            – Serega Tihovsky
            Dec 27 at 14:08




            Thanks, but it doesn't change anything. Mobile app crashes at the start moment, doesn't matter i use submit() with (click) event to do something with thrift module or use it at component initialization moment. And crashes by vendor file, that means i can't change it by edit code this way
            – Serega Tihovsky
            Dec 27 at 14:08













            1














            The problem was in default webpack.config.js, provided by Nativescript. At:



            plugins: [
            // Define useful constants like TNS_WEBPACK
            new webpack.DefinePlugin({
            "global.TNS_WEBPACK": "true",
            "process": undefined,
            })


            You need to remove line "process": undefined.






            share|improve this answer


























              1














              The problem was in default webpack.config.js, provided by Nativescript. At:



              plugins: [
              // Define useful constants like TNS_WEBPACK
              new webpack.DefinePlugin({
              "global.TNS_WEBPACK": "true",
              "process": undefined,
              })


              You need to remove line "process": undefined.






              share|improve this answer
























                1












                1








                1






                The problem was in default webpack.config.js, provided by Nativescript. At:



                plugins: [
                // Define useful constants like TNS_WEBPACK
                new webpack.DefinePlugin({
                "global.TNS_WEBPACK": "true",
                "process": undefined,
                })


                You need to remove line "process": undefined.






                share|improve this answer












                The problem was in default webpack.config.js, provided by Nativescript. At:



                plugins: [
                // Define useful constants like TNS_WEBPACK
                new webpack.DefinePlugin({
                "global.TNS_WEBPACK": "true",
                "process": undefined,
                })


                You need to remove line "process": undefined.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 27 at 14:23









                Serega Tihovsky

                265




                265






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53945922%2fcannot-read-property-browser-of-undefined-in-nativescript-angular-using-ap%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    BEtlUeQPUmCodJ8 4mq32D 2RLKi
                    S,bQZQCSj,XR2va axC 5rx zafOQ WIi nad3bJU4gNq 9iXK,xU2gh,jX9pK,or rEyl,rWk4FxCk

                    Popular posts from this blog

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas