Vite: Getting `ReferenceError: TextEncoder is not defined` on react template

Created on 23 Jun 2020  路  4Comments  路  Source: vitejs/vite

Hi,
I was simply trying vite react template, and after having installed and simply running npm run dev I get:

ben @ tmp/react-vite > npm run dev

> [email protected] dev /Users/ben/pro/tmp/react-vite
> vite

vite v1.0.0-beta.4

  Dev server running at:
  > Local:    http://localhost:3000/
  > Network:  http://192.168.8.111:3000/
  > Network:  http://10.212.134.212:3000/


  ReferenceError: TextEncoder is not defined
      at createChannel (/Users/ben/pro/tmp/react-vite/node_modules/esbuild/lib/main.js:102:17)
      at Object.startService (/Users/ben/pro/tmp/react-vite/node_modules/esbuild/lib/main.js:338:47)
      at ensureService (/Users/ben/pro/tmp/react-vite/node_modules/vite/dist/esbuildService.js:38:36)
      at Object.exports.transform (/Users/ben/pro/tmp/react-vite/node_modules/vite/dist/esbuildService.js:49:27)
      at app.use (/Users/ben/pro/tmp/react-vite/node_modules/vite/dist/server/serverPluginEsbuild.js:16:58)
      at process._tickCallback (internal/process/next_tick.js:68:7)


pending triage

Most helpful comment

I'm the author of esbuild, the library that is crashing. It looks like TextEncoder works on node LTS but not on node 10.x. Upgrading to node LTS should fix the crash.

I just published a new version of esbuild that doesn't require TextEncoder. Updating vite to use esbuild 0.5.11 should fix this crash for all users on node 10.x.

All 4 comments

You didn't provide any information from the issue template. A reproduction would be really helpful.

@MarvinRudolph you are right sorry.

Here is a repo https://github.com/ciaoben/react-vite

I simply launched these commands from on my mac (10.15.4) with node v10.13.0:

mkdir react-vite
cd react-vite
npm init vite-app --template react
npm i
npm run dev

I'm the author of esbuild, the library that is crashing. It looks like TextEncoder works on node LTS but not on node 10.x. Upgrading to node LTS should fix the crash.

I just published a new version of esbuild that doesn't require TextEncoder. Updating vite to use esbuild 0.5.11 should fix this crash for all users on node 10.x.

@evanw Thanks for your point error.

Was this page helpful?
1 / 5 - 2 ratings

Related issues

stefnotch picture stefnotch  路  3Comments

gliheng picture gliheng  路  4Comments

maxxcs picture maxxcs  路  3Comments

Dykam picture Dykam  路  4Comments

ais-one picture ais-one  路  3Comments