0

I've come to the community to ask for help since I have been facing this problem for the last few days and can't seem to find any answers on the topic.

I've just converted my fully working HTML (with scripts) to React and everything seems to work apart from the scripts. I've tried loading them in the main index.html, as helmets, in the JS page itself, and nothing seems to work. Currently this is what my code looks like [IN THE INDEX.HTML FILE]

  ```<body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>


    <script src="../src/pageScript.js" async defer></script>
    <script src="../js/scripts.min.js" async defer></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js" async defer></script>

    <script type="text/javascript">
        $(document).keyup(function(e) {
          if (e.key === "Escape") {
            $('.modal').removeClass('modal-show');
            $('.content').removeClass('content-blurred');
            $('body').removeClass('no-scroll');
          }
        });

      $(function(){

      
        // Provider card slider
        $('.slider').flickity({
          pauseAutoPlayOnHover: false,
          prevNextButtons: false,
          cellAlign: 'center',
          draggable:  false,
          freeScroll: false,
          wrapAround: true,
          pageDots: false,
          autoPlay: 3000,
        });

        // Imbox zero slider
        $('.zero-slider').flickity({
          pauseAutoPlayOnHover: false,
          prevNextButtons: false,
          cellAlign: 'center',
          freeScroll: false,
          wrapAround: false,
          draggable: false,
          pageDots: false,
          autoPlay: 3000,
          fade: true,
        });

        // Open & close modal
        $('.modal-toggle').click(function(){
          $('.modal').toggleClass('modal-show');
          $('.content').toggleClass('content-blurred');
          $('body').toggleClass('no-scroll');
        });

        // Reserve username form
        $(".form").submit(function(e) {
          e.preventDefault();
          var $form = $(this);
          $.post($form.attr("action"), $form.serialize()).then(function() {
            $('.form-content').addClass('form-content-hide');
            $('.success').addClass('success-show');
          });
        });

        // Save user's first name
        $(".form").submit(function(e) {
          e.preventDefault();
          var value = $("#firstName").val();
          $('.first-name').text("Thank you," + " " + value + "!");
        });

        // Feather icons
        feather.replace()

        // ScrollReveal
        ScrollReveal().reveal('.hero, .title, .screen, .features, .cards, .zero-slider', {
          distance: '40px',
          duration: 2000,
          mobile: false,
          reset: false,
          opacity: 0
        });

      });
    </script>

  </body>```

In my website console, I get the errors: Uncaught SyntaxError: Unexpected token '<' (at pageScript.js:1:1)

&

scripts.min.js:1 Uncaught SyntaxError: Unexpected token '<' (at scripts.min.js:1:1)

&

Uncaught ReferenceError: $ is not defined

Any support will be greatly appreciated!

  • It's not a great idea to mix jquery and react like this – evolutionxbox Aug 08 '22 at 10:34
  • Usually an `Uncaught SyntaxError: Unexpected token '<' (at file.js:1:1)` means you're getting an HTML error page back in the response (Generally a 404) Check your dev tools for the network response. – DBS Aug 08 '22 at 10:37
  • @evolutionxbox How would you recommend to do it? – darkage531 Aug 08 '22 at 10:39
  • https://stackoverflow.com/questions/38518278/how-to-use-jquery-with-reactjs – evolutionxbox Aug 08 '22 at 10:43
  • @evolutionxbox I don't think there's any React code in there... – Andy Aug 08 '22 at 10:46
  • @DBS You're correct with the fact that I'm, getting a 404 error. It's for a css.map file I don't have yet. I have created one and entered dummy code {"version":1,"sources":[],"names":[],"mappings":"","file":"home.css","sourceRoot":""} and the 404 error is gone, but I still get the unexpected token syntax errors. – darkage531 Aug 08 '22 at 10:50
  • Well, it depends on the error, but assuming it's a 404 then you'll need to work out why the server isn't returning the file. It might be that your `src='...'` is wrong, or that haven't uploaded the file to the server, or the file exists but is not publicly accessible... the list is quite long and unfortunately very hard for us to help with without seeing the issue for ourselves. – DBS Aug 08 '22 at 10:51
  • @DBS I don't have a css.map file in the project directory which would be why it throws a 404 error, how would I go about making one? – darkage531 Aug 08 '22 at 11:10

0 Answers0