Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack-vue-uniapp打包后,mp3.js报错_parseInt2 is not defined,beta-amr-engine.js报错Cannot read property 'slice' of null #79

Closed
yaoxin2017 opened this issue Mar 25, 2020 · 12 comments
Labels
bug Something isn't working

Comments

@yaoxin2017
Copy link

在uniapp里使用该项目时,控制台出现错误log:
beta-amr-engine.js:451 Uncaught TypeError: Cannot read property 'slice' of null
at parseJSFunc (beta-amr-engine.js:451)
at beta-amr-engine.js:458
at beta-amr-engine.js:400
at Object.../../../../../11.workspace/vueWorkSpace/supervisorUniApp/recorder-core/src/engine/beta-amr-engine.js (beta-amr-engine.js:8)
at webpack_require (bootstrap:766)
at fn (bootstrap:129)
at Object.../../../../../11.workspace/vueWorkSpace/supervisorUniApp/main.js (main.js:14)
at webpack_require (bootstrap:766)
at fn (bootstrap:129)
at Object.0 (log.js:47)

我查了这行代码 451行是这个:var parsed = jsfunc.toString().match(sourceRegex).slice(1);

求教怎么处理?

以下是我使用方式,使用nmp下载源码后,源码位于node_modules目录下,我将recorder-core(以及该文件夹的内部文件)复制到 我的uniapp项目跟目录,并在main.js中引入(如下import所示),这时在控制台就会出现 上面的 错误log,显示 beta-amr-engine 的451行报错。

import RecordApp from 'recorder-core/src/app-support/app'
import 'recorder-core'
import 'recorder-core/src/engine/mp3'
import 'recorder-core/src/engine/mp3-engine'
//ios 微信支持
import 'recorder-core/src/app-support/app-ios-weixin-support'
import 'recorder-core/ios-weixin-config.js'
import 'recorder-core/src/engine/beta-amr'
import 'recorder-core/src/engine/beta-amr-engine'

@xiangyuecn
Copy link
Owner

参考:
BenzLeung/benz-amr-recorder#17
BenzLeung/benz-amr-recorder#9

晚点我尝试更新一下beta-amr-engine这个文件

@yaoxin2017
Copy link
Author

感谢作者的回复。

现在有个新问题,就是我暂时去掉了ios微信录音的支持,此时没有报错了。
但是在录音时有了新的错误: Uncaught ReferenceError: _parseInt2 is not defined

源码里没有_parseInt2 ,通过浏览器控制台查看对应的是 源码的parseInt,我截图了,麻烦看下

报错详情的截图.zip

@yaoxin2017
Copy link
Author

补充一下,目前依赖如下:

import Recorder from 'recorder-core'
import 'recorder-core/src/engine/mp3'
import 'recorder-core/src/engine/mp3-engine'

@xiangyuecn
Copy link
Owner

#78

@xiangyuecn
Copy link
Owner

看起来像是babel给js代码加料(投毒)了。麻烦发一下你的webpack配置(发一份能在现问题的源码就更好了,你看看能不能新建一个能一样产生问题的简单demo)

@xiangyuecn
Copy link
Owner

beta-amr-engine这个文件我看了一下benz-amr-recorder的作者只更新了一次
BenzLeung/benz-amr-recorder@f791056
我看了一下他的变更,改动的代码并没有任何实际的作用,虽然抑制住了null,但并没有解决根源性的问题,新版本不匹配直接退出不知道会不会产生新的bug。sourceRegex的老版本匹配范围包含了新版本的匹配范围,新版本能匹配到范围反而更小了。以前他更新的时候我就检查过代码,所以不会把beta-amr-engine更新到他的新版本。

我怀疑你那编译出来的js函数变成 function xxx(){}这种形式,导致sourceRegex不能匹配。就跟parseInt一样,被改写成了别的函数

@xiangyuecn xiangyuecn changed the title 在uniapp中使用时,源代码内部报错Cannot read property 'slice' of null webpack-vue-uniapp打包后,mp3.js报错_parseInt2 is not defined,beta-amr-engine.js报错Cannot read property 'slice' of null Mar 26, 2020
@xiangyuecn xiangyuecn added the bug Something isn't working label Mar 26, 2020
@yaoxin2017
Copy link
Author

我用的是DCloud的HbuilderX开发工具( 官网:https://www.dcloud.io/ ) 这个开发工具新建uniapp项目里面没有像vue-cli那样有详细的配置文件,HbuilderX虽然也是用webpack打包,但是把一些细节封装隐藏起来了

@xiangyuecn
Copy link
Owner

你那试试把下面两个地方的 parseInt改成 window.parseInt 试试看还会不会被编译成_parseInt2,如果都正常了那我就把库里的源码更新一下

Recorder/src/engine/mp3.js

Lines 254 to 258 in 6dd3e96

sampleRate&&(sampleRate=sampleRate[parseInt(b4.substr(4,2),2)]);
var bitRate=[ //lamejs -> Tables.bitrate_table
[0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160] //MPEG 2 2.5
,[0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]//MPEG 1
][version==1?1:0][parseInt(b4.substr(0,4),2)];

@yaoxin2017
Copy link
Author

改后报错:
8b4c30ae-b819-40de-948c-61eb39e10ed1:14221 Uncaught ReferenceError: window is not defined
at Object.rm (8b4c30ae-b819-40de-948c-61eb39e10ed1:14221)
at Object.fn (8b4c30ae-b819-40de-948c-61eb39e10ed1:14268)
at onmsg (8b4c30ae-b819-40de-948c-61eb39e10ed1:14190)

@yaoxin2017
Copy link
Author

recorder.zip
这个是uniapp项目,里面只集成了 该录音库,解压后用Hbuilder打开就行了,打开后在开发工具右边点击 预览 就会自动编译运行了,浏览器 用 http://localhost:8080/#/ 也可以打开,点击录音在浏览器控制台就可以看到错误信息了

@xiangyuecn
Copy link
Owner

dd1aafb 两个问题都已修复。

beta-amr-engine里面这段jsfunc的分解代码其实压根一点用处都没有,最外面这层函数没有地方用到了,直接剔除了这段带有隐患的源码。

parseInt应该是babel-polyfill中配置的原因,Hbuilder的锅,应该是配置了对parseInt、parseFloat的处理(全局下的parseInt又没有说会废弃,毛用处都没有,不像Promise还有点卵用这种)😂

@yaoxin2017
Copy link
Author

感谢作者!已在uniapp上实测,问题已解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants