【问题标题】:NextJs 13 & Framer Motion: Module not found: Can't resolve 'v8'NextJs 13 & Framer Motion:找不到模块:无法解析 \'v8\'
【发布时间】:2022-12-26 01:13:16
【问题描述】:

不断收到此错误,我有我的app directory 并尝试为页面转换设置动画,但无论我对 framer motion 做什么,我都会收到此 v8 错误。找不到周围的很多东西,有没有人有解决办法?

'use client';

import { Poppins } from '@next/font/google';
import { useRouter, React } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { getSession } from '../lib/session';
import Header from '../components/Header';
import Footer from '../components/Footer';
import AuthContext from '../components/AuthContext';
import '../styles/globals.css';

// If loading a variable font, you don't need to specify the font weight
const poppins = Poppins({
  weight: '500',
});

export default async function RootLayout({ children }) {
  const session = await getSession();
  const router = useRouter();
  return (

    <html lang="en" className={poppins.className}>
      <head />
      <body>

        <AuthContext session={session}>
          <Header />
          <AnimatePresence exitBeforeEnter>
            <motion.div
              key={router.route}
              initial="initialState"
              animate="animateState"
              exit="exitState"
              transition={{
                duration: 0.75,
              }}
              variants={{
                initialState: {
                  opacity: 0,
                  clipPath: 'polygon(0 0, 100% 0, 100% 100%, 0% 100%)',
                },
                animateState: {
                  opacity: 1,
                  clipPath: 'polygon(0 0, 100% 0, 100% 100%, 0% 100%)',
                },
                exitState: {
                  clipPath: 'polygon(50% 0, 50% 0, 50% 100%, 50% 100%)',
                },
              }}
            >
              {children}
            </motion.div>
          </AnimatePresence>
        </AuthContext>
        {session ? <Footer /> : ''}
      </body>
    </html>
  );
}

也许它与 nextAuth 有关?不确定

【问题讨论】:

  • 我认为你的问题与在服务器端调用 framerMotion 有关,因为 v8 是浏览器的引擎......但不幸的是我还没有使用 framer motion 来做出反应......
  • @Wraithy 我在上面添加了 'use client'; 使其成为客户端呈现的组件,但我仍然收到错误

标签: reactjs next.js framer-motion


【解决方案1】:

您应该将 v8 添加到您的项目中。

npm install v8 / yarn add v8

【讨论】:

    【解决方案2】:

    您可以尝试检查是否安装了所有导入的模块。我使用 framer-motion 但我从未见过这样的错误

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center
    猜你喜欢
    • 2021-08-01
    • 2021-05-17
    • 2021-04-07
    • 2021-09-14
    • 1970-01-01
    • 2017-10-23
    • 2021-10-16
    • 1970-01-01
    • 2022-12-14
    相关资源
    最近更新 更多