I am new to React. I have added it to a project using the information on this site:
https://reactjs.org/docs/add-react-to-a-website.html
Run npm init -y (if it fails, here’s a fix)
Run npm install babel-cli@6 babel-preset-react-app@3
Then,
npx babel --watch src --out-dir . --presets react-app/prod
Whenever I try adding a module it gives me:
Uncaught SyntaxError: Cannot use import statement outside a module.
Here is how I am importing :
import { PostcodeLookup } from "@ideal-postcodes/postcode-lookup"
(I've tried this at the top of my react js file and in a seperate script file called in a componentDidMount() method via:
const script = document.createElement("script");
script.src = "my_script.js";
script.async = true;
document.body.appendChild(script);
Thank you.