Skip to content
This repository was archived by the owner on Dec 30, 2021. It is now read-only.

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

Closed
wiktor-obrebski opened this issue Jun 8, 2020 · 3 comments

Comments

@wiktor-obrebski
Copy link

wiktor-obrebski commented Jun 8, 2020

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
Copy link
Owner

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
Copy link
Owner

Fixed in c84d51b

@wiktor-obrebski
Copy link
Author

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants