Uncaught ReferenceError: require is not defined at cheerio.js:52019 Community Moderator Electionangular2 uncaught ReferenceError require is not defined “boot.ts”How can I new an Object or call function in const declaration in Typescript 2.0.10?Uncaught ReferenceError: require is not defined atAngular 4 “Property does not exist on type component”Could not find local “typescript” package.The “@ngtools/webpack” package Angular 2Require is not defined on reflect-metadata - __webpack_require__ issueRequired request body is missing : front request issuesUncaught TypeError: Cannot read property 'parse' of undefined when requiring a libraryAngular 7 ERROR ReferenceError: SystemJS is not definedAngular - ERROR ReferenceError: config is not defined

What are the consequences of changing the number of hours in a day?

"Marked down as someone wanting to sell shares." What does that mean?

What is it called when someone votes for an option that's not their first choice?

Nested Dynamic SOQL Query

Asserting that Atheism and Theism are both faith based positions

Why didn’t Eve recognize the little cockroach as a living organism?

How old is Nick Fury?

PTIJ: Why do we make a Lulav holder?

PTIJ: Which Dr. Seuss books should one obtain?

When should a starting writer get his own webpage?

Animating wave motion in water

Air travel with refrigerated insulin

Homology of the fiber

Are hand made posters acceptable in Academia?

Determine voltage drop over 10G resistors with cheap multimeter

What is the tangent at a sharp point on a curve?

Unfrosted light bulb

Could any one tell what PN is this Chip? Thanks~

Can other pieces capture a threatening piece and prevent a checkmate?

UK Tourist Visa- Enquiry

Imaginary part of expression too difficult to calculate

How to find the largest number(s) in a list of elements, possibly non-unique?

Have the tides ever turned twice on any open problem?

Should I be concerned about student access to a test bank?



Uncaught ReferenceError: require is not defined at cheerio.js:5



2019 Community Moderator Electionangular2 uncaught ReferenceError require is not defined “boot.ts”How can I new an Object or call function in const declaration in Typescript 2.0.10?Uncaught ReferenceError: require is not defined atAngular 4 “Property does not exist on type component”Could not find local “typescript” package.The “@ngtools/webpack” package Angular 2Require is not defined on reflect-metadata - __webpack_require__ issueRequired request body is missing : front request issuesUncaught TypeError: Cannot read property 'parse' of undefined when requiring a libraryAngular 7 ERROR ReferenceError: SystemJS is not definedAngular - ERROR ReferenceError: config is not defined










1















I'm trying to add a 'shopping' section to my Angular 6 application. This shopping section will contain a search bar which will search Amazon and return a list of whatever the user wants. For example, the user searches a hammer, the list will contain hammers.
To do this, I am trying to web scrape by using Cheerio. When trying to declare this in my TypeScript file:



declare var require: any;
const request = require("request");
const cheerio = require("cheerio");


I get the following error in my webpage:
enter image description here



Any help would be greatly appreciated, or any advice on an alternative solution to what I'm trying to achieve would be very helpful.










share|improve this question




























    1















    I'm trying to add a 'shopping' section to my Angular 6 application. This shopping section will contain a search bar which will search Amazon and return a list of whatever the user wants. For example, the user searches a hammer, the list will contain hammers.
    To do this, I am trying to web scrape by using Cheerio. When trying to declare this in my TypeScript file:



    declare var require: any;
    const request = require("request");
    const cheerio = require("cheerio");


    I get the following error in my webpage:
    enter image description here



    Any help would be greatly appreciated, or any advice on an alternative solution to what I'm trying to achieve would be very helpful.










    share|improve this question


























      1












      1








      1








      I'm trying to add a 'shopping' section to my Angular 6 application. This shopping section will contain a search bar which will search Amazon and return a list of whatever the user wants. For example, the user searches a hammer, the list will contain hammers.
      To do this, I am trying to web scrape by using Cheerio. When trying to declare this in my TypeScript file:



      declare var require: any;
      const request = require("request");
      const cheerio = require("cheerio");


      I get the following error in my webpage:
      enter image description here



      Any help would be greatly appreciated, or any advice on an alternative solution to what I'm trying to achieve would be very helpful.










      share|improve this question
















      I'm trying to add a 'shopping' section to my Angular 6 application. This shopping section will contain a search bar which will search Amazon and return a list of whatever the user wants. For example, the user searches a hammer, the list will contain hammers.
      To do this, I am trying to web scrape by using Cheerio. When trying to declare this in my TypeScript file:



      declare var require: any;
      const request = require("request");
      const cheerio = require("cheerio");


      I get the following error in my webpage:
      enter image description here



      Any help would be greatly appreciated, or any advice on an alternative solution to what I'm trying to achieve would be very helpful.







      angular typescript angular6






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 20:59









      mruanova

      1,88421431




      1,88421431










      asked Mar 7 at 18:57









      RafteryRaftery

      284




      284






















          2 Answers
          2






          active

          oldest

          votes


















          0














          If you're running your code in the browser, you will want to use more than just the typescript compiler to build your project. This is because the browser doesn't natively support calls to require. Not to worry, don't let this deter you! There are tons of mature tools that address this specific problem by bundling up the code being required into file(s) that can be used in the browser.



          There's a whole section about these build tools in the documentation: https://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html






          share|improve this answer























          • I personally use webpack.js.org

            – Wex
            Mar 7 at 19:13


















          0














          TypeScript uses import as opposed to require.



          The correct statement is: import * as cheerio from 'cheerio';.



          I would also recommend installing the type Cheerio from here.



          Furthermore, try doing things the "Angular way". Angular comes with a bunch of pre-packaged tools including Request from @angular/common/http read more about it here.



          The easiest way to come about your scraper, supposing that you don't wish to have any backend implementation running on the side, is to make a service with public methods to would allow you to keep everything in that one file therefore keeping your component code clean and "to the point".






          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%2f55050975%2funcaught-referenceerror-require-is-not-defined-at-cheerio-js5%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









            0














            If you're running your code in the browser, you will want to use more than just the typescript compiler to build your project. This is because the browser doesn't natively support calls to require. Not to worry, don't let this deter you! There are tons of mature tools that address this specific problem by bundling up the code being required into file(s) that can be used in the browser.



            There's a whole section about these build tools in the documentation: https://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html






            share|improve this answer























            • I personally use webpack.js.org

              – Wex
              Mar 7 at 19:13















            0














            If you're running your code in the browser, you will want to use more than just the typescript compiler to build your project. This is because the browser doesn't natively support calls to require. Not to worry, don't let this deter you! There are tons of mature tools that address this specific problem by bundling up the code being required into file(s) that can be used in the browser.



            There's a whole section about these build tools in the documentation: https://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html






            share|improve this answer























            • I personally use webpack.js.org

              – Wex
              Mar 7 at 19:13













            0












            0








            0







            If you're running your code in the browser, you will want to use more than just the typescript compiler to build your project. This is because the browser doesn't natively support calls to require. Not to worry, don't let this deter you! There are tons of mature tools that address this specific problem by bundling up the code being required into file(s) that can be used in the browser.



            There's a whole section about these build tools in the documentation: https://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html






            share|improve this answer













            If you're running your code in the browser, you will want to use more than just the typescript compiler to build your project. This is because the browser doesn't natively support calls to require. Not to worry, don't let this deter you! There are tons of mature tools that address this specific problem by bundling up the code being required into file(s) that can be used in the browser.



            There's a whole section about these build tools in the documentation: https://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 7 at 19:11









            WexWex

            11.5k95091




            11.5k95091












            • I personally use webpack.js.org

              – Wex
              Mar 7 at 19:13

















            • I personally use webpack.js.org

              – Wex
              Mar 7 at 19:13
















            I personally use webpack.js.org

            – Wex
            Mar 7 at 19:13





            I personally use webpack.js.org

            – Wex
            Mar 7 at 19:13













            0














            TypeScript uses import as opposed to require.



            The correct statement is: import * as cheerio from 'cheerio';.



            I would also recommend installing the type Cheerio from here.



            Furthermore, try doing things the "Angular way". Angular comes with a bunch of pre-packaged tools including Request from @angular/common/http read more about it here.



            The easiest way to come about your scraper, supposing that you don't wish to have any backend implementation running on the side, is to make a service with public methods to would allow you to keep everything in that one file therefore keeping your component code clean and "to the point".






            share|improve this answer





























              0














              TypeScript uses import as opposed to require.



              The correct statement is: import * as cheerio from 'cheerio';.



              I would also recommend installing the type Cheerio from here.



              Furthermore, try doing things the "Angular way". Angular comes with a bunch of pre-packaged tools including Request from @angular/common/http read more about it here.



              The easiest way to come about your scraper, supposing that you don't wish to have any backend implementation running on the side, is to make a service with public methods to would allow you to keep everything in that one file therefore keeping your component code clean and "to the point".






              share|improve this answer



























                0












                0








                0







                TypeScript uses import as opposed to require.



                The correct statement is: import * as cheerio from 'cheerio';.



                I would also recommend installing the type Cheerio from here.



                Furthermore, try doing things the "Angular way". Angular comes with a bunch of pre-packaged tools including Request from @angular/common/http read more about it here.



                The easiest way to come about your scraper, supposing that you don't wish to have any backend implementation running on the side, is to make a service with public methods to would allow you to keep everything in that one file therefore keeping your component code clean and "to the point".






                share|improve this answer















                TypeScript uses import as opposed to require.



                The correct statement is: import * as cheerio from 'cheerio';.



                I would also recommend installing the type Cheerio from here.



                Furthermore, try doing things the "Angular way". Angular comes with a bunch of pre-packaged tools including Request from @angular/common/http read more about it here.



                The easiest way to come about your scraper, supposing that you don't wish to have any backend implementation running on the side, is to make a service with public methods to would allow you to keep everything in that one file therefore keeping your component code clean and "to the point".







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 7 at 19:59









                double-beep

                2,88041129




                2,88041129










                answered Mar 7 at 19:26









                mzaleskimzaleski

                135




                135



























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55050975%2funcaught-referenceerror-require-is-not-defined-at-cheerio-js5%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







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme