Vercel 导致 500:内部服务器错误(在本地主机上运行)

2023-12-25

我正在创建一个页面,可以在其中概述我的所有笔记/摘要。

笔记的页面是转换为动态文件中使用的 HTML 的 Markdown 文件。
“/note”页面是一页,包含一组所有笔记。现在我想实现一个搜索功能来对笔记进行排序。

当我跑步时npm run dev它启动本地主机并且一切正常(还有搜索栏)。 但是,当我推送到我的 Github 存储库并在 Vercel 上部署时,它会给出 500:内部服务器错误。

在 Vercel 日志中,您可以看到 /note 是服务器端页面,因为它具有“λ”符号。

18:40:46.860 λ /注释 12.2 kB 104 kB

是不是router.push("/notes")这是造成这个还是其他什么原因?

源代码:https://github.com/Wilmox/portfolio https://github.com/Wilmox/portfolio
Vercel 托管页面:https://portfolio-p3hy5j90k-wilmox.vercel.app/ https://portfolio-p3hy5j90k-wilmox.vercel.app/

Here is also a gif of the problem in action: 500: Internal Server Error

我希望有一个人可以帮助我 :)

我的notes/index.js 的代码:

import Head from 'next/head';
import Link from 'next/link';
import styles from '../../styles/Home.module.css';
import Footer from '../../components/Footer.js';
import Navigation from '../../components/Navigation';
import { Rating } from '@material-ui/core';
import Chip from '../../components/Chip.js';

import noteStyle from '../../styles/Notes.module.css';

import { getAllNotes } from '../../lib/data';
import Search from '../../components/Search';

export default function Notes({ notes }) {
  return (
    <div id="top" className={styles.container}>
      <Head>
      </Head>

      <main className={styles.main}>
        <section>
          <Navigation />
        </section>
        <section className={noteStyle.noteSection}>
          <header>
            <h1>Notes & Summaries</h1>
            <p>These are notes I&apos;ve taken or summaries I&apos;ve made of the things I read or listen to. Parts may come straight from the source, while others are written by me. <br />
            I do this to get the author&apos;s high-level idea or to brush up on something for later, or for people who don&apos;t feel like reading / listening to a whole book.</p>
          </header>
          
          <Search />

          <div className={noteStyle.notes}>
            {notes.map((note) => (
              <Link key={note.slug} href={`/note/${note.slug}`}>
                <a key={note.slug} className={noteStyle.noteCard}>
                  <h2 key="title">{note.title}</h2>
                  <h3 key="author">{note.author}</h3>
                  <p key="abstract">
                    {note.abstract}
                  </p>
                  <div className={noteStyle.aboutNote}>
                    <Rating key="rating" className={noteStyle.rating} name="half-rating-read" defaultValue={note.rating} precision={0.5} readOnly />
                    <Chip key="label" className={noteStyle.noteChip} bgColor={note.labelColors[0]} text={note.labelText[0]} icon={note.labelIcons[0]} />
                  </div>
                </a>
              </Link>
            ))}

          </div>
        </section>
      </main>
      <Footer />
    </div>
  )
}

export async function getServerSideProps(context) {
  const allNotes = getAllNotes();

  const searchTerm = context.query.search ?? "";

  let searchNotes = allNotes;

  if (searchTerm != null) {
    searchNotes =  searchNotes.filter((note) => {
      //Searches in title, author & abstract data field for a match with the query
      return note.data.title.toLowerCase().includes(searchTerm.toLowerCase()) || note.data.author.toLowerCase().includes(searchTerm.toLowerCase()) || note.data.abstract.toLowerCase().includes(searchTerm.toLowerCase())
    });
  }

  
  
  return {
    props: {
      //Here data serialising (dates, urls, ...),
      notes: searchNotes.map(({ data, content, slug }) => ({
        ...data,
        content,
        slug,
      })),

    },
  };
};

Search.js 组件的代码

import style from './Search.module.css';
import SearchIcon from '@mui/icons-material/Search';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/router'

export default function Search() {
    const [input, setInput] = useState('');
    const router = useRouter();

    useEffect(() => {
        if (input != '') {
            router.push('/notes?search=' + input);
            console.log("You searched for ", input);
        } else {
            router.push('/notes');
        }
      }, [input]);

    const search = (e) => {
        e.preventDefault();
        setInput(e.target.value);
    }

    return (
        <div className={style.search}>
                <SearchIcon className={style.search__inputIcon}/>
                <input type="text" placeholder="Search for a note..." value={input} onChange={search} />
        </div>
    )
}

Vercel 构建日志:

18:40:23.357    Cloning github.com/Wilmox/portfolio (Branch: main, Commit: afef201)
18:40:23.965    Cloning completed: 607.51ms
18:40:23.981    Analyzing source code...
18:40:25.095    Installing build runtime...
18:40:26.928    Build runtime installed: 1.833s
18:40:29.439    Looking up build cache...
18:40:29.580    Build cache found. Downloading...
18:40:32.275    Build cache downloaded [37.34 MB]: 2694.570ms
18:40:33.436    Installing dependencies...
18:40:33.440    Detected `package-lock.json` generated by npm 7...
18:40:34.913    up to date in 1s
18:40:34.913    156 packages are looking for funding
18:40:34.913      run `npm fund` for details
18:40:34.922    Detected Next.js version: 11.1.0
18:40:34.927    Running "npm run build"
18:40:35.193    > [email protected] /cdn-cgi/l/email-protection build
18:40:35.193    > next build
18:40:35.905    info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
18:40:36.056    info  - Checking validity of types...
18:40:37.907    ./pages/index.js
18:40:37.907    28:9  Warning: Custom fonts not added at the document level will only load for a single page. This is discouraged. See https://nextjs.org/docs/messages/no-page-custom-font.  @next/next/no-page-custom-font
18:40:37.908    72:15  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
18:40:37.908    85:15  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
18:40:37.908    ./pages/note/[slug].js
18:40:37.908    26:9  Warning: Custom fonts not added at the document level will only load for a single page. This is discouraged. See https://nextjs.org/docs/messages/no-page-custom-font.  @next/next/no-page-custom-font
18:40:37.908    ./pages/notes/index.js
18:40:37.909    24:9  Warning: Custom fonts not added at the document level will only load for a single page. This is discouraged. See https://nextjs.org/docs/messages/no-page-custom-font.  @next/next/no-page-custom-font
18:40:37.909    ./pages/projects/index.js
18:40:37.909    19:9  Warning: Custom fonts not added at the document level will only load for a single page. This is discouraged. See https://nextjs.org/docs/messages/no-page-custom-font.  @next/next/no-page-custom-font
18:40:37.910    32:15  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
18:40:37.910    45:15  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
18:40:37.910    58:15  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
18:40:37.910    71:15  Warning: Image elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
18:40:37.910    ./components/Search.js
18:40:37.910    17:10  Warning: React Hook useEffect has a missing dependency: 'router'. Either include it or remove the dependency array.  react-hooks/exhaustive-deps
18:40:37.911    info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
18:40:37.911    info  - Creating an optimized production build...
18:40:44.074    info  - Compiled successfully
18:40:44.076    info  - Collecting page data...
18:40:45.109    info  - Generating static pages (0/8)
18:40:45.558    info  - Generating static pages (2/8)
18:40:46.768    info  - Generating static pages (4/8)
18:40:46.784    info  - Generating static pages (6/8)
18:40:46.830    info  - Generating static pages (8/8)
18:40:46.832    info  - Finalizing page optimization...
18:40:46.859    Page                                                           Size     First Load JS
18:40:46.859    ┌ ○ /                                                          3.62 kB        99.1 kB
18:40:46.859    ├   └ css/72e3b52ac8c0e0986525.css                             2.5 kB
18:40:46.859    ├   /_app                                                      0 B            67.4 kB
18:40:46.859    ├ ○ /404                                                       194 B          67.6 kB
18:40:46.859    ├ λ /api/hello                                                 0 B            67.4 kB
18:40:46.860    ├ ● /note/[slug] (3945 ms)                                     2.97 kB        95.1 kB
18:40:46.860    ├   └ css/0825cd3181548be7acd8.css                             2.6 kB
18:40:46.860    ├   ├ /note/a-brief-history-of-time (1423 ms)
18:40:46.860    ├   ├ /note/rich-dad-poor-dad (1232 ms)
18:40:46.860    ├   ├ /note/how-to-win-friends-and-influence-people (1044 ms)
18:40:46.860    ├   └ /note/the-magic-of-thinking-big
18:40:46.860    ├ λ /notes                                                     12.2 kB         104 kB
18:40:46.860    ├   └ css/48d66f471e6a5bb11874.css                             2.13 kB
18:40:46.860    └ ○ /projects                                                  1.35 kB        93.7 kB
18:40:46.860        └ css/bf38675255d10289bb03.css                             1.39 kB
18:40:46.860    + First Load JS shared by all                                  67.4 kB
18:40:46.860      ├ chunks/framework.2191d1.js                                 42.4 kB
18:40:46.860      ├ chunks/main.9399b7.js                                      23.6 kB
18:40:46.860      ├ chunks/pages/_app.4003d7.js                                586 B
18:40:46.860      ├ chunks/webpack.ddd010.js                                   822 B
18:40:46.860      └ css/9b9279095ab98c9a275c.css                               752 B
18:40:46.862    λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
18:40:46.862    ○  (Static)  automatically rendered as static HTML (uses no initial props)
18:40:46.862    ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
18:40:46.862       (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
18:40:46.862    Next.js Analytics is enabled for this production build. You'll receive a Real Experience Score computed by all of your visitors.
18:40:48.949    Traced Next.js server files in: 1.983s
18:40:59.634    Created all serverless functions in: 10.686s
18:41:00.140    Uploading build outputs...
18:41:01.138    Deploying build outputs...
18:41:06.098    Build completed. Populating build cache...
18:41:29.887    Uploading build cache [37.28 MB]...
18:41:30.595    Build cache uploaded: 708.32ms
18:41:31.120    Done with "package.json"


经过 1 年零 9 个月的时间,我成功解决了这个问题。
显然,这是一个众所周知的脆弱性在 NextJS 11 中。该漏洞的完整描述可以在CVE-2021-43803 https://nvd.nist.gov/vuln/detail/CVE-2021-43803

因此,要解决此问题,您只需升级到NextJS 12.1.0或以上。

我感谢大家在试图提出解决方案时提供的帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Vercel 导致 500:内部服务器错误(在本地主机上运行) 的相关文章

随机推荐

  • 带下划线前缀的受保护属性

    Like public foo null bar 10 protected stuff null moreStuff 5 似乎很多人都这样做 为什么 这不是不一致的命名吗 就像某些 PHP 函数一样 这是 php5 之前的旧约定 Php4
  • Ipython raw_input 可以解决吗?

    我正在运行一个Python程序 它想要接受raw input 而Ipython笔记本不这样做 已知的限制 实现该功能的推荐方法是什么 解决方法 我想做的是能够运行程序 接受输入并响应 将根据检索到的信息确定选择 并提示输入用户 ID 和密码
  • 我应该使用哪种方法来手动引导我的 AngularJS?

    我看到了以下内容 angular bootstrap document TodoApp angular bootstrap angular element body 0 TodoApp AngularJS 文档也提到了这一点 我不太明白 a
  • VS Code 的 EditorConfig 不起作用

    我使用 VS Code 作为编辑器 我们有一个 editorconfig其中包含格式配置的文件 我们都在编辑器中使用扩展 EditorConfig 来格式化 HTML 和 CSS 常规内容 我已经从这里安装了 VS Code 的扩展 Edi
  • 以编程方式设置 java.awt.headless=true

    我正在尝试设置java awt headless true在应用程序启动期间 但似乎我来得太晚了 非无头模式已经开始 static System setProperty java awt headless true java awt Gra
  • 在 FFMPEG 中对数据流和视频进行编码

    我想将一些专有数据 它是每帧的序列化无符号 64 位整数 编码到视频容器 mp4 作为数据流 但我无法找到任何人执行此操作的说明 教程 我唯一能找到的是这个 它描述了如何创建数据流 用户显然没有成功https lists libav org
  • 如何在 HTML 中创建泪滴?

    如何创建这样的形状以显示在网页上 我不想使用images因为它们在缩放时会变得模糊 我尝试过CSS tear display inline block transform rotate 30deg border 5px solid gree
  • Plotly:并排条形图和饼图

    我想使用并排绘制条形图和饼图subplot函数在plotly然而 在图形的中心绘制了一个大饼图 覆盖了条形图 这是示例代码 Animals lt c giraffes orangutans monkeys SF Zoo lt c 20 14
  • Android Native 在 /system/lib/libskia.so 崩溃(位图处理)

    我需要帮助解决影响 Play 商店中应用程序的错误 Play 开发者控制台上的崩溃报告 此崩溃仅限于某些安卓4 4 devices 无法在模拟器上重现崩溃 堆栈跟踪发生在本机代码 而不是 Java 上 因此很难看出此错误是在哪里调用的 研究
  • 使用 jcifs 读取文件的最简单方法

    我正在尝试使用外部从网络共享读取文件jcifs图书馆 https jcifs samba org 我能找到的大多数用于读取文件的示例代码都非常复杂 甚至可能不必要 我找到了一个简单的方法write到如下所示的文件 有没有办法使用类似的语法读
  • 声明框架中结构的简单协议一致性

    是否可以声明 struct 是在框架中定义的结构 它基本上符合在我的应用程序中定义的协议 举例来说 我有一个 API 它为框架中建模的一些小部件声明结构 public struct VagueWidget public let temper
  • 如何比较 Boost 几何形状?

    我有 2 个 升压 几何 模型 环 我试图判断它们是否相同 是否有内置的增强几何比较函数 方法可以为我解决这个问题 boost geometry equals a b 报告两个几何图形在空间上是否相等
  • WSO2 ESB 5 中的动态 json-eval 表达式

    我正在尝试使用动态生成的 json eval 来处理 JSONPayload 以选择特定的酒店对象 下面提到的直接 json eval 工作得很好 直接 json eval 表达式 json eval content hotelcode A
  • 从 HTML5 存储打开 PDF

    我想将 pdf 文件客户端存储在 HTML5 存储之一 indexedDB 或 localstorage 中 然后稍后使用 adobe reader 打开它们 场景如下 用户访问了我的网站并将一堆 pdf 下载到存储中 稍后 用户重新访问该
  • 获取现有的 NSLayoutConstraint 宽度?

    我正在尝试使用自动布局为 Cocoa 中的控件设置动画 现在 我可以设置 constraint animator setConstant newWidth 有效 但我怎样才能得到正确的约束呢 With self constraints 你可
  • 没有适用于应用内购买的信息。稍后再试。 21105

    昨天 当我从任何地方测试我的应用程序时 这个错误开始出现 打电话时发生这种情况restoreCompletedTransactions 在应用程序启动时 此错误是什么意思 我可以采取什么措施来避免此错误 这是苹果的内部服务器造成的 根据我几
  • 如何在 Visual Studio 2017 中运行 MSBuild 包目标

    我的问题类似于this https stackoverflow com questions 40661918 how do you create a nuget package from a net core msbuild project
  • 函数式编程语言的静态分析器,例如Scheme

    我很少看到像Racket Scheme这样的函数式编程语言的静态分析器 我什至怀疑是否有 我想为函数式语言编写一个静态分析器 比如Scheme Racket 我该怎么办 是的 有一些关于像Scheme这样的动态语言的静态分析的工作 例如 请
  • Networkx 中的图论

    我现在开始使用这个界面 我有一些 Python 经验 但没什么广泛的 我正在计算一个小图的传递性和社区结构 import networkx as nx G nx read edgelist data delimiter nodetype s
  • Vercel 导致 500:内部服务器错误(在本地主机上运行)

    我正在创建一个页面 可以在其中概述我的所有笔记 摘要 笔记的页面是转换为动态文件中使用的 HTML 的 Markdown 文件 note 页面是一页 包含一组所有笔记 现在我想实现一个搜索功能来对笔记进行排序 当我跑步时npm run de