NextJS 中间件服务器错误:尝试导出“TextDecoderStream”的可为空值

问题描述 投票:0回答:1

我已经设置了一个简单的 nextjs 应用程序,其中包含带有应用程序路由(nextjs

1.0.4
)和源目录的bun(版本
bun create next-app
13.5.4
)。我想包含一个只允许来自某些 IP 的流量的中间件,但是如果我在
middleware.ts
目录(根据文档应该在哪里)中有
/src
文件,无论文件中包含什么,我都会收到以下错误:

Error: Attempt to export a nullable value for "TextDecoderStream"
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
defineProperties
file:<PROJECT>/node_modules/next/dist/compiled/edge-runtime/index.js
addPrimitives
file:<PROJECT>/node_modules/next/dist/compiled/edge-runtime/index.js
extend
file:<PROJECT>/node_modules/next/dist/compiled/edge-runtime/index.js
new VM
file:<PROJECT>/node_modules/next/dist/compiled/edge-runtime/index.js
new EdgeVM
file:<PROJECT>/node_modules/next/dist/compiled/edge-runtime/index.js
<anonymous>
file:<PROJECT>/node_modules/next/dist/server/web/sandbox/context.js (196:64)

目录结构如下:

/node_modules
/public
/src
/src/app
/src/lib
/src/middleware.ts
/<config_and_env_files...>
/bun.lockb
/next-env.d.ts
/next.config.js
/package.json
/tsconfig.json

有什么方法可以修复此错误,以便我可以将 IP 列入白名单,或者是否有更好的方法将 IP 列入白名单,以便我可以解决该问题? 我尝试用谷歌搜索这个问题,但没有太多关于这个错误的主题。

node.js typescript next.js middleware bun
1个回答
0
投票

这就是 PopOs 上对我有用的东西

  1. 安装nodejs - 确保你获得最新的稳定版本
  2. 安装npm
  3. cd 进入项目
  4. 运行
    npm run dev
    并停止
  5. 奔跑
    bun run dev

Bun 还没有实现

TextDecoderStream
。他们说 “让所有 API 接受字符串而不是让单独的编码器/解码器流通过输入会更快。”在这条推文中

我很想知道为什么会这样。

© www.soinside.com 2019 - 2024. All rights reserved.