`@snowpack/plugin-dotenv`, `jest`: "Cannot use 'import.meta' outside a module"
wiktor-obrebski opened this issue · comments
Wiktor Obrębski commented
I use @snowpack/app-template-react-typescript
template and @snowpack/plugin-dotenv
for .env
file load.
const BaseUrl: string = (import.meta as any).env.SNOWPACK_PUBLIC_API_URL;
It works in npm start
, but when I try to run test I got following error:
/home/psychowico/Projects/alcarin/web/src/api/client.ts:10
const BaseUrl = import.meta.env.SNOWPACK_PUBLIC_API_URL;
^^^^
SyntaxError: Cannot use 'import.meta' outside a module
how I can fix it?
Fred K. Schott commented
Ah, great catch. Until Jest works with ESM, we'll need to add a babel plugin for Jest that converts import meta into {env: process.env}
in a way that matches Snowpack's env object.
Fred K. Schott commented
Fixed in c84d51b
Wiktor Obrębski commented
Thank you!