FredKSchott / create-snowpack-app

The all-in-one app template for Snowpack. [moved]
https://www.snowpack.dev
Other
727 stars 96 forks source link

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

Closed wiktor-obrebski closed 4 years ago

wiktor-obrebski commented 4 years ago

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?

FredKSchott commented 4 years ago

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.

FredKSchott commented 4 years ago

Fixed in c84d51b

wiktor-obrebski commented 4 years ago

Thank you!