npm install iconv-lite --save
const iconv = require('iconv-lite');
// 假设你有一个GB2312编码的Buffer或Uint8Array类型的变量gb2312Data
let gb2312Data = ...; // 这里应该是你的GB2312编码数据
// 使用iconv-lite将GB2312编码的数据转换为汉字
let utf8Data = iconv.decode(gb2312Data, 'gb2312');
console.log(utf8Data); // 输出转换后的汉字字符串
引入之后编译就报错
页面【pages/deviceDetection/deviceDetection]错误:
Error: module 'miniprogram_npm/safer-buffer/buffer.js' is not defined, require args is 'buffer'
at q (WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1)
at r (WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1)
at __REQUIRE__ (index.js?t=wechat&s=1726808096631&v=5578d0db45387fe60c6c624bc121c13e:20)
at safer.js:77
at Object.func (safer.js:5)
at __REQUIRE__ (index.js?t=wechat&s=1726808096631&v=5578d0db45387fe60c6c624bc121c13e:40)
at safer.js:77
at safer.js:77
at WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1
at p.runWith (WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1)(env: Windows,mp,1.06.2405020; lib: 3.5.6)
(anonymous) @ VM3865:11
Error: module 'miniprogram_npm/safer-buffer/buffer.js' is not defined, require args is 'buffer'
at q (WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1)
at r (WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1)
at __REQUIRE__ (index.js?t=wechat&s=1726808096631&v=5578d0db45387fe60c6c624bc121c13e:20)
at safer.js:77
at Object.func (safer.js:5)
at __REQUIRE__ (index.js?t=wechat&s=1726808096631&v=5578d0db45387fe60c6c624bc121c13e:40)
at safer.js:77
at safer.js:77
at WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1
at p.runWith (WASubContext.js?t=wechat&s=1726808096631&v=3.5.6:1)(env: Windows,mp,1.06.2405020; lib: 3.5.6)
Component is not found in path "wx://not-found".(env: Windows,mp,1.06.2405020; lib: 3.5.6)
解决了吗兄弟,我这边也是这个问题