🔎 What you'll see
Uncaught SyntaxError: Cannot use import statement outside a module
🤔 Why it happens
import/export only work in "module" scripts. You'll see this error if you load the file with a plain <script src> or open it by double-clicking.
🛠️ How to fix it
- Add type="module" to the script tag: <script type="module" src="...">.
- Modules are blocked on file:// addresses, so open the page through a local server or your deployed URL.
- If the code imports packages installed with npm, you need a build tool like Vite. If you'd rather have a single HTML file, ask the AI to switch to CDN links.
🤖 What to ask your AI
Replace the parts in [ ] with your own details, then paste it in.
I'm getting 'Cannot use import statement outside a module'. I want to run it as a single HTML file with no build tools. Here's my current code: [code]. Give me the complete file rewritten to use a CDN.
Other errors
CORS errorThe browser blocks your page from fetching data from another site404 Not FoundThe address or file can't be foundundefined / Cannot read properties of undefinedReading a property of a value that isn't thereis not definedUsing a name that was never declaredSyntaxErrorBrackets or quotes don't match upExposed API keyYou put a secret key in your code or on GitHubMixed ContentAn https page loads something from an http addressBlank white pageYou deployed it and all you see is a blank screenis not a functionCalling something that isn't a functionUnexpected token < in JSONYou expected JSON but got HTMLfavicon.ico 404The console shows a 404 for favicon.icoData disappears when I refreshYour to-dos or scores aren't being savedPage looks broken or tiny on phonesFine on a computer, weird on mobilegit push rejectedA "rejected" / non-fast-forward errornpm: command not foundYour terminal says npm or node doesn't existPort 3000 is already in useYour dev server says the port is takenEnvironment variables (.env) aren't loadingYou put your API key in .env but it comes out undefinedThe AI keeps failing to fix the same errorYou ask for a fix and nothing changes