Netlify throwing error when import/export modules, why?

I have an API key hidden in a file, I’m not using dotenv to do this, and I’m importing them into my javascript file via ES6 modules. Netlify allows build commands to build this when the app is deployed.

cd scripts && echo -e "const API_KEY = 'blahblahblah'; const HASH_KEY = 'blahblahblah'; const TIME_STAMP = 'ts=1'; const URL_ENDPOINT='blahblahblah';\n\nexport API_KEY, HASH_KEY, TIME_STAMP, URL_ENDPOINT;" > apikey.js

That is what I put into Netlify’s deploy settings.

When I go to the deployed site, I get "Uncaught syntax error: unexpected token export".

The file is made correctly in the sources tab of the console. I’m at a loss for what I’ve done incorrectly, or what Netlify isn’t interpreting correctly.

64 thoughts on “Netlify throwing error when import/export modules, why?”

Leave a Comment