NodeJS NextJS Middleware服务器错误:尝试导出“TextDecoderStream”的可空值

iih3973s  于 5个月前  发布在  Node.js
关注(0)|答案(1)|浏览(68)

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

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列入白名单,以便我可以绕过这个问题?我试图在谷歌上搜索这个问题,但没有太多关于此错误的主题。

ltqd579y

ltqd579y1#

这就是我在PopOs上的工作
1.安装nodejs -确保您获得最新的稳定版本
1.安装npm

  1. cd进入项目
    1.运行npm run dev并停止它
    1.运行bun run dev
    Bun还没有实现TextDecoderStream。他们说“让所有的API都接受字符串,而不是让一个单独的编码器/解码器流通过输入,这样会更快。”
    我很想知道为什么这会有效。

相关问题