dotenv 18.0.9 parse used in a browser page under Vite dev, with vite-plugin-node-polyfills (buffer + Buffer global), as in the CO2 AI frontend.
Steps:
npm installnpm run devand open the printed URL- The page throws
Invalid or unexpected token.
What is going on: Vite's dep optimizer bundles dotenv/dist/index.cjs, which begins with #!/usr/bin/env node. The polyfill plugin injects import statements at the top of that bundle, so the shebang ends up on line 5 of an ES module, where it is a syntax error. With dotenv 17.4.2 the shebang is not present in the optimized output.