FredKSchott / create-snowpack-app

The all-in-one app template for Snowpack. [moved]

Home Page:https://www.snowpack.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`@snowpack/plugin-dotenv`, `jest`: "Cannot use 'import.meta' outside a module"

wiktor-obrebski opened this issue · comments

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?

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.

Thank you!