I developed my projects on CodePen and everything works normally. But when I export the files and try to use them on my machine or GitHub Pages it just doesn’t work.
On my machine and on GitHub Pages the HTML and CSS load normally, but the JS file doesn’t work. This problem occurred with two projects, one using jQuery and the other using jQuery and React.
CodePen exports only three files: index.html, style.css and script.js. Do I need to use some special file to make it work outside of CodePen?
On console I get:
Uncaught ReferenceError: $ is not defined at script.js:1:1 (Project using jQuery)
Uncaught SyntaxError: Cannot use import statement outside a module (Project using React and jQuery
Thank you so much! I was putting jQuery script at the end of the body.
I put the type="module" on the script, but now the console show Uncaught SyntaxError: Unexpected token '<' (at VM29 script.js:21:7) even though the code appears to be correct:
You’re using jsx so you must also include a tool called babel, which will transpile your jsx into JavaScript that the browser can interpret.
Try to follow the guide in the React docs, it tells you all the scripts you need to use (especially the " Optional: Try React with JSX" section at the bottom).