javascript - 未处理的 promise 拒绝警告 : ReferenceError: TextEncoder is not defined in NextJS 12

标签 javascript node.js reactjs npm next.js

我正在尝试使用 NextJS 12 和 tailwind css 模板构建一个 Spotify 克隆。
我使用此命令创建项目:npx create-next-app -e with-tailwindcss spotify-2 .
该项目已成功创建,但在我运行 npm run dev 时做了cd spotify-2之后,我收到以下错误:

> @ dev /home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
(node:14702) UnhandledPromiseRejectionWarning: ReferenceError: TextEncoder is not defined
    at /home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-writer.browser.development.server.js:67:19
    at Object.<anonymous> (/home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-writer.browser.development.server.js:900:5)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2/node_modules/next/dist/compiled/react-server-dom-webpack/writer.browser.server.js:6:20)
(node:14702) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14702) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ReferenceError: TextEncoder is not defined
    at /home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-writer.browser.development.server.js:67:19
    at Object.<anonymous> (/home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-writer.browser.development.server.js:900:5)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/aishik-ubuntu/MEGAsync/Programming On Ubuntu/My Projects/NextJS Projects/spotify-2/node_modules/next/dist/compiled/react-server-dom-webpack/writer.browser.server.js:6:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `next dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/aishik-ubuntu/.npm/_logs/2021-11-26T18_33_22_412Z-debug.log
我现在该怎么办?

最佳答案

我有同样的错误,但使用 typescript 模板

npx create-next-app@latest --typescript
我正在运行一个非常旧的 Node 版本 10。我升级到版本 16 LTS,然后它运行没有错误。您可以使用以下命令检查您的版本:
node -v
站点状态 Node 版本 12.22.0 的系统要求。
https://nextjs.org/docs/getting-started#system-requirements

关于javascript - 未处理的 promise 拒绝警告 : ReferenceError: TextEncoder is not defined in NextJS 12,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70128771/

相关文章:

javascript - JQuery 事件处理程序未通过面包屑链接附加

javascript - 防止缓存 JS 文件

http - 使用 Node.js 中的 http.get 库对 vows 进行异步测试

java - 无法将我的请求参数发送到bluemix部署的node.js

javascript - 在 PHP 中转义字符串以供 JavaScript 使用

javascript - 如何为整个 Liferay 网站或门户添加 javascript 加载 (jQuery)?

node.js - NodeJS https服务器没有响应

javascript - 如何对子组件进行 React forceUpdate()?

reactjs - 为什么这个组件会从受控切换到不受控? - react

javascript - 直接调用函数draw时得到不同的输出? react 俄罗斯方 block