网站制作学习网Python→正文:python 调用 nodejs extjs ReferenceError: TextEncoder is not defined
字体:

python 调用 nodejs extjs ReferenceError: TextEncoder is not defined

Python 2022/6/30 13:34:54  点击:不统计



 在ubuntu 命令中运行python 调用nodejs 出现下面的错误

 

ReferenceError: TextEncoder is not defined

execjs._exceptions.ProgramError: ReferenceError: TextEncoder is not defined

出现上述问题的原因是 在 nodejs 11版本一下不支持 TextEncoder,需要用其他方式去代替

需要升级到 版本11以上即可。

 

ubuntu nodejs 升级


网上还有一种方法,没有测试
项目的nodeJs版本低于v11,可以安装moduletext-encodin。
$ npm install text-encoding
加在入口文件
// These have been added in NodeJS v11, so good idea is to check first
if (typeof TextEncoder !== 'function') {
    const TextEncodingPolyfill = require('text-encoding');
    window.TextEncoder = TextEncodingPolyfill.TextEncoder;
    window.TextDecoder = TextEncodingPolyfill.TextDecoder;
}

转载%77%77%77请%2E%66%6F%72%61%73%70%2E%63%6E注明

·上一篇:python 时间类 >>    ·下一篇:PackagesNotFoundError: The following packages are not available from c >>
推荐文章
最新文章