Project build failed with "import.meta.env" Vite #1840
Replies: 4 comments 13 replies
-
We have a related discussion in Jotai: pmndrs/jotai#1974 |
Beta Was this translation helpful? Give feedback.
-
I'm trying to reproduce the issue with minimal vite setup: $ yarn create vite
✔ Project name: … vite-react-zustand
✔ Select a framework: › React
✔ Select a variant: › TypeScript
$ cd vite-react-zustand
$ yarn
$ yarn add zustand
$ nvim src/App.tsx # Modify it like the diff below
$ yarn build
$ ag -Q '[DEPRECATED] The `destroy` method' dist/assets/ --- src/App.tsx.bak 2023-06-10 13:48:21.000000000 +0900
+++ src/App.tsx 2023-06-10 13:49:43.000000000 +0900
@@ -1,10 +1,15 @@
-import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
+import { create } from 'zustand'
+
+const useCountStore = create<{ count:number; inc:()=>void }>((set) => ({
+ count: 0,
+ inc: () => set((state) => ({ count: state.count + 1 })),
+}))
function App() {
- const [count, setCount] = useState(0)
+ const { count, inc } = useCountStore()
return (
<>
@@ -18,7 +23,7 @@
</div>
<h1>Vite + React</h1>
<div className="card">
- <button onClick={() => setCount((count) => count + 1)}>
+ <button onClick={inc}>
count is {count}
</button>
<p> Found this in the asset dir: Then: $ yarn add https://pkg.csb.dev/pmndrs/zustand/commit/d908d1ad/zustand
$ yarn build
$ ag -Q '[DEPRECATED] The `destroy` method' dist/assets/ Not bound the console.warn statement. This confirms #1845 fixes the simple case. |
Beta Was this translation helpful? Give feedback.
-
i get [Passing vanilla store will be unsupported, instead use |
Beta Was this translation helpful? Give feedback.
-
I'm running into this issue. |
Beta Was this translation helpful? Give feedback.
-
We are receiving project build errors when deploying our application
Specifically in Zustand's
node_module
files,esm/index.mjs
,esm/vanilla.mjs
, andesm/shallow.mjs
with statements like the code block below where it seems that the code is trying to assert the truthiness of
import.meta.env
However it is
undefined
which seems to cause the following error trace.Here is a link to a brief but relevant article regarding this error message
If instead we refactor to remove the initial import.meta.env with just the below, i believe it then builds succesfully.
Has anyone else encountered these messages before with
Vite
?Vite: 4.3.8
Zustand: 4.3.8
Zustand-Computed: 1.3.5
Beta Was this translation helpful? Give feedback.
All reactions