UnhandledPromiseRejectionWarning:ReferenceError:TextEncoder 未在 NextJS 12 中定义 [英] UnhandledPromiseRejectionWarning: ReferenceError: TextEncoder is not defined in NextJS 12

查看:15
本文介绍了UnhandledPromiseRejectionWarning:ReferenceError:TextEncoder 未在 NextJS 12 中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 NextJS 12 和 tailwind css 模板构建一个 Spotify 克隆.

I am trying to build a spotify-clone using NextJS 12 and tailwind css template.

我使用这个命令来创建项目:npx create-next-app -e with-tailwindcss spotify-2.

I used this command to create the project : npx create-next-app -e with-tailwindcss spotify-2.

该项目已成功创建,但是当我在执行 cd spotify-2 后运行 npm run dev 时,出现以下错误:

The project was created susscessfully but as I ran npm run dev after doing a cd spotify-2, I am getting the following error :

> @ 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 模板

I had the same error but with the typescript template

npx create-next-app@latest --typescript

我正在运行一个非常旧的节点版本 10.我升级到版本 16 LTS,然后它运行没有错误.您可以使用以下命令检查您的版本:

I was running a very old node version 10. I upgraded to version 16 LTS and then it ran without error. You can check your version with this command:

node -v

站点状态节点版本 12.22.0 的系统要求.https://nextjs.org/docs/getting-started#system-requirements

System requirements on the site state node version 12.22.0. https://nextjs.org/docs/getting-started#system-requirements

这篇关于UnhandledPromiseRejectionWarning:ReferenceError:TextEncoder 未在 NextJS 12 中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆