0

我的代码在我运行它时的反应是这样的,它说 TextDecoderStream() & TextEncoderStream() 没有定义。

async function connect() {
const port = await navigator.serial.requestPort();
// - Wait for the port to open.
await port.open({ baudRate: 115200 });
console.log("Open");


 let decoder = new TextDecoderStream();
  inputDone = port.readable.pipeTo(decoder.writable);
  inputStream = decoder.readable;

 const encoder = new TextEncoderStream();
  outputDone = encoder.readable.pipeTo(port.writable);
  outputStream = encoder.writable;

 let reader = inputStream.getReader();
}

出错

    src\Components\play\Remote\Ace\RemoteSection\RemoteSection.js
    Line 453:23:  'TextDecoderStream' is not defined  no-undef
     Line 457:25:  'TextEncoderStream' is not defined  no-undef

如果我删除流并且只使用 TextDecoder() 和 TextEncoder() 那么它显示

 Unhandled Rejection (TypeError): Failed to execute 'pipeTo' on 
 'ReadableStream': parameter 1 is not of type 'WritableStream'.

  Unhandled Rejection (TypeError): Cannot read properties of undefined 
  (reading 'pipeTo')
4

1 回答 1

0

TextDecoderStream并且TextEncoderStream根据https://chromestatus.com/features/4881011259211776在 Chrome 71 中可用。

我怀疑你的问题是一个 linter 问题。您可能想尝试https://eslint.org/docs/rules/no-undef中记录的这个 eslint 规则。

   // eslint-disable-next-line no-undef
   let decoder = new TextDecoderStream();

   ...

   // eslint-disable-next-line no-undef
   const encoder = new TextEncoderStream();
于 2022-01-06T15:21:00.780 回答