Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import.meta.env is not supported #2182

Closed
tux21b opened this issue Apr 15, 2022 · 2 comments
Closed

import.meta.env is not supported #2182

tux21b opened this issue Apr 15, 2022 · 2 comments

Comments

@tux21b
Copy link

tux21b commented Apr 15, 2022

I am not really familiar with this import.meta stuff, but importing jotai leads to the following warnings:

▲ [WARNING] "import.meta" is not available in the configured target environment ("chrome58", "edge18", "firefox57", "safari11") and will be empty

    ../node_modules/jotai/esm/index.mjs:66:7:
      66 │   if ((import.meta.env && import.meta.env.MODE) !== "production") {
         ╵        ~~~~~~~~~~~

▲ [WARNING] "import.meta" is not available in the configured target environment ("chrome58", "edge18", "firefox57", "safari11") and will be empty

    ../node_modules/jotai/esm/index.mjs:66:26:
      66 │   if ((import.meta.env && import.meta.env.MODE) !== "production") {
         ╵                           ~~~~~~~~~~~

The code only checks the existence of import.meta.env so i guess import.meta should always exist. It seems to work with other bundlers (webpack).

@hyrious
Copy link

hyrious commented Apr 15, 2022

import.meta.env is not in the scope of esbuild, you will have to add your own --define:import.meta.env={}. The jotai package makes the assumption that their users are using webpack. But other bundlers (including rollup) do not agree with that.

If there exists one common env variable, it has to be process.env.NODE_ENV. But someone also wants to remove that. So I guess there's no perfect solution.

@tux21b
Copy link
Author

tux21b commented Apr 15, 2022

Thanks for your quick reply. I was able to solve my problem in the meantime.

Apparently import.meta.env is supported by esbuild, but it needs ES2020 as mentioned here:
#1492

I was able to fix it by updating the supported engines slightly:

api.EngineChrome: 58 -> 64
api.EngineFirefox: 57 -> 62
api.EngineSafari: 11 -> 11.1
api.EngineEdge: 18 -> 79

Now everything seems to work as expected. Thanks :)

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

No branches or pull requests

2 participants