我已将 useEffect 配置为仅在其依赖项更改时运行:
useEffect(() => {
localStorage.setItem("cart", JSON.stringify(cart));
}, [cart])
Run Code Online (Sandbox Code Playgroud)
但是当组件第一次渲染时。useEffect 钩子为什么会调用?
我使用 Nextjs 框架创建了一个项目。
\n当我使用命令运行项目时npm run dev,我的项目运行正常,没问题。
但是当我运行命令npm run build来构建项目时,之后我找不到构建文件夹。
以下是向我展示的完整报告:
\n\n\xce\xbb npm 运行构建
\n\n\ndastshafa-final@0.1.0 构建\n下一个构建
\ninfo - 检查类型的有效性
\n./pages/cartProcess/index.js 13:6 警告:React Hook useEffect 缺少依赖项:\'displayNavbar\'。包含它或删除\n依赖数组。如果“displayNavbar”更改过于频繁,请找到定义它的父组件并将该定义包装在 useCallback 中。react-hooks/exhaustive-deps 31:11 警告:请勿使用\n。请改用“next/image”中的图像。请参阅:\n https://nextjs.org/docs/messages/no-img-elem ent\n@next/next/no-img-element
\n./pages/index.js 14:6 警告:React Hook useEffect 缺少\n依赖项:\'setDisplayNavbar\'。包含它或删除依赖数组。如果“setDisplayNavbar”更改过于频繁,请找到定义它的父\n组件并将该定义包装在 useCallback 中。\nreact-hooks/exhaustive-deps
\n./components/navbar.js 58:21 警告:请勿使用 . 请使用\n来自“next/image”的图像。请参阅:\n https://nextjs.org/docs/messages/no-img-elem ent\n@next/next/no-img-element 101:17 警告:passHref 丢失。请参阅:\n https://nextjs.org/docs/messages/link-passhref \n@next/next/link-passhref 117:9 警告:passHref 丢失。请参阅:\n https://nextjs.org/docs/messages/link-passhref \n@next/next/link-passhref 118:11 警告:请勿使用 . 请使用\n来自“next/image”的图像。请参阅:\n https://nextjs.org/docs/messages/no-img-ele ment\n@next/next/no-img-element 118:11 警告:img 元素必须有一个\nalt …
根据这个链接
我已经使用以下代码片段配置了我的 package.json 项目文件:
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"export": "npm run build && next export -o _static",
"lint": "next lint"
},
Run Code Online (Sandbox Code Playgroud)
npm run export但是当我在终端中运行命令:时,它会导致错误:
Failed to compile.
HookWebpackError: EMFILE: too many open files, open 'E:\Projects\React\dastshafa-final\node_modules\@mui\icons-material\SixKOutlined.js'
at makeWebpackError (E:\Projects\React\dastshafa-final\node_modules\next\dist\compiled\webpack\bundle5.js:41664:9)
at E:\Projects\React\dastshafa-final\node_modules\next\dist\compiled\webpack\bundle5.js:25354:12
at eval (eval at create (E:\Projects\React\dastshafa-final\node_modules\next\dist\compiled\webpack\bundle5.js:140346:10), <anonymous>:27:1)
at E:\Projects\React\dastshafa-final\node_modules\next\dist\compiled\webpack\bundle5.js:22805:26
at E:\Projects\React\dastshafa-final\node_modules\next\dist\build\webpack\plugins\next-trace-entrypoints-plugin.js:327:36
-- inner error --
Error: EMFILE: too many open files, open 'E:\Projects\React\dastshafa-final\node_modules\@mui\icons-material\SixKOutlined.js'
caused by plugins in Compilation.hooks.processAssets
Error: EMFILE: too …Run Code Online (Sandbox Code Playgroud)