Jaeho Lee
Jaeho Lee

Reputation: 523

Node.js TextDecoder same code but in AWS environment has encoding not supported problem

I use following code for decoding some data

const { q } = req.query
    const { data } = await axios({
      url: GOOGLE_AUTOCOMPLETE_ENDPOINT,
      method: 'get',
      params: {
        client: 'chrome',
        hl: 'ko',
        gl: 'kr',
        q,
      },
      responseType: 'arraybuffer',
    })

    // data decoding
    const decoder = new TextDecoder('EUC-KR')
    const decodedData = decoder.decode(data)

When i test in local using npm run dev it's totally fine.

but when i deploy same code to AWS Environment It fails with the error message

{"error":{"code":"ERR_ENCODING_NOT_SUPPORTED","type":"RangeError","message":"The \"EUC-KR\" encoding is not supported","date":"2021-10-08T00:25:03.672Z","debug":{"stack":["RangeError [ERR_ENCODING_NOT_SUPPORTED]: The \"EUC-KR\" encoding is not supported","    at new TextDecoder (internal/encoding.js:396:15)","    at getYoutubeAutoCompleteHandler (/usr/src/app/lib/api/keywords/youtubeAutoComp.js:38:21)","    at runMicrotasks (<anonymous>)","    at processTicksAndRejections (internal/process/task_queues.js:97:5)","    at async wrapperFn (/usr/src/app/lib/utils/asyncWrapper.js:11:7)"]},"request":"/api/v2/keywords/youtube/autoComplete?q=t"}}

I have no idea what i did miss..

AWS using pm2-runtime server.ts command in Docker image

Upvotes: 1

Views: 555

Answers (1)

Jaeho Lee
Jaeho Lee

Reputation: 523

It was Node.js version problem

I was using Node v14 in local.

and AWS using Node v12

when i change Node to v12 in local

TextDecoder is not working

Upvotes: 1

Related Questions