Shopify-cli app "TextEncoder is not defined" error


As soon as I entered the “shopify app serve” command, this error occurs at “running server”

[nodemon] starting node ./server/index.js
┃ info - Loaded env from /home/worm/Shopify_apps/seo-dev/.env
┃ (node:63571) UnhandledPromiseRejectionWarning: ReferenceError: TextEncoder is not defined
┃ at /home/worm/Shopify_apps/seo-dev/node_modules/next/dist/compiled/react-server-dom-webpack/cjs/react-server-dom-webpack-writer.browser.development.server.js:67:19
┃ at Object. (/home/worm/Shopify_apps/seo-dev/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 Module._compile (/home/worm/Shopify_apps/seo-dev/node_modules/pirates/lib/index.js:99:24)
┃ at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
┃ at Object.newLoader [as .js] (/home/worm/Shopify_apps/seo-dev/node_modules/pirates/lib/index.js:104:7)
┃ 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)
┃ (node:63571) 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:63571) [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.
┃ error - Failed to load next.config.js, see more info here https://nextjs.org/docs/messages/next-config-error
┃ (node:63571) UnhandledPromiseRejectionWarning: Error: Not supported
┃ at Object.loadConfig [as default] (/home/worm/Shopify_apps/seo-dev/node_modules/next/server/config.ts:582:20)
┃ (node:63571) 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: 3)
┃ [nodemon] clean exit - waiting for changes before restart

I’ve tried editing the “node-modules >> whatdwg-url >> dist >> encoding.js” (const { TextEncoder, TextDecoder } = require(“util”); ) but the error exists.

need a solution

Thank you

This is a node version error, upgrade your node to at least v14.

If you need v10 to work on older legacy code like slate for example, I recommend using nvm(node version manager) to handle switching between versions.

Note that there are different version for windows and IOS.

1 Like