首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UnhandledPromiseRejectionWarning: ReferenceError: TextEncoder没有在NextJS 12中定义

UnhandledPromiseRejectionWarning: ReferenceError: TextEncoder没有在NextJS 12中定义
EN

Stack Overflow用户
提问于 2021-11-26 18:38:48
回答 1查看 4.5K关注 0票数 6

我试图构建一个spotify克隆使用NextJS 12和顺风css模板。

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

该项目创建得非常出色,但当我在执行npm run dev后运行cd spotify-2时,我得到了以下错误:

代码语言:javascript
复制
> @ 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

我现在该怎么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-27 01:45:34

我也犯了同样的错误,但是使用了类型记录模板。

代码语言:javascript
复制
npx create-next-app@latest --typescript

我运行的是一个非常老的节点版本10。我升级到了16版本LTS,然后它运行时没有出错。您可以使用以下命令检查您的版本:

代码语言:javascript
复制
node -v

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

票数 15
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70128771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档