收藏
回答

小程序中引用tencentcloud-sdk-nodejs-tts提示缺失crypto?

通过npm install tencentcloud-sdk-nodejs-tts --save 并构建npm

在小程序中引用:

const tencentcloud = require("tencentcloud-sdk-nodejs-tts")

编辑报错:

【pages/index/index]错误:

 Error: module 'miniprogram_npm/tencentcloud-sdk-nodejs-common/crypto.js' is not defined, require args is 'crypto'

    at C (wxmodule.patch.js?t=wechat&s=1695219134014&v=2.19.4:1)

    at n (wxmodule.patch.js?t=wechat&s=1695219134014&v=2.19.4:1)

    at __REQUIRE__ (index.js:27)

    at abstract_client.js:233

    at Object.func (abstract_client.js:233)

    at __REQUIRE__ (index.js:47)

    at abstract_client.js:233

    at Object.func (sign.js:2)

    at __REQUIRE__ (index.js:47)

    at sdk_version.js:1(env: macOS,mp,1.06.2307260; lib: 2.19.4)

(anonymous) @ VM1823:1114

doWhenAllScriptLoaded @ VM1770:1160

(anonymous) @ VM1770:15

loadBabelModules @ assubloader.js:1

async function (async)

loadBabelModules @ assubloader.js:1

window.loadBabelMod @ VM1753:9

(anonymous) @ possibleConstructorReturn.js:2

WAServiceMainContext.js:2 Uncaught FrameworkError 

 module 'miniprogram_npm/tencentcloud-sdk-nodejs-common/crypto.js' is not defined, require args is 'crypto' 

 Error: module 'miniprogram_npm/tencentcloud-sdk-nodejs-common/crypto.js' is not defined, require args is 'crypto'

    at C (http://127.0.0.1:48731/appservice/__dev__/wxmodule.patch.js?t=wechat&s=1695219134014&v=2.19.4:1:5584)

    at n (http://127.0.0.1:48731/appservice/__dev__/wxmodule.patch.js?t=wechat&s=1695219134014&v=2.19.4:1:4741)

    at __REQUIRE__ (http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:27:34)

    at http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:620:12

    at Object.func (http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:505:18)

    at __REQUIRE__ (http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:47:23)

    at http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:475:12

    at Object.func (http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:89:18)

    at __REQUIRE__ (http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:47:23)

    at http://127.0.0.1:48731/appservice/miniprogram_npm/tencentcloud-sdk-nodejs-common/index.js:80:12(env: macOS,mp,1.06.2307260; lib: 2.19.4)

o @ WAServiceMainContext.js:2

c @ VM9 asdebug.js:1

r @ VM9 asdebug.js:1

window.onerror @ VM1753:9

doWhenAllScriptLoaded @ VM1770:1160

(anonymous) @ VM1770:15

loadBabelModules @ assubloader.js:1

error (async)

t.default @ VM1753:9

(anonymous) @ VM1753:9

(anonymous) @ VM1753:9

(anonymous) @ VM1753:9

WAServiceMainContext.js:2 Error: module 'miniprogram_npm/tencentcloud-sdk-nodejs-common/crypto.js' is not defined, require args is 'crypto'

    at C (wxmodule.patch.js?t=wechat&s=1695219134014&v=2.19.4:1)

    at n (wxmodule.patch.js?t=wechat&s=1695219134014&v=2.19.4:1)

    at __REQUIRE__ (index.js:27)

    at abstract_client.js:233

    at Object.func (abstract_client.js:233)

    at __REQUIRE__ (index.js:47)

    at abstract_client.js:233

    at Object.func (sign.js:2)

    at __REQUIRE__ (index.js:47)

    at sdk_version.js:1(env: macOS,mp,1.06.2307260; lib: 2.19.4)


小程序中如何正确引用tencentcloud-sdk-nodejs


回答关注问题邀请回答
收藏

1 个回答

  • Young nbe
    Young nbe
    2023-09-22

    根据你提供的错误信息,问题出在“tencentcloud-sdk-nodejs-common/crypto.js”模块未定义。这可能是由于腾讯云SDK的某些版本与你的小程序环境存在兼容性问题。

    解决此问题,你可以考虑以下方案:

    宠物百科

    更新腾讯云SDK版本:在安装腾讯云SDK时,使用npm install tencentcloud-sdk-nodejs-tts@latest --save命令,安装最新版本的SDK。

    检查依赖项:确保你的项目中没有重复的依赖项,尤其是不兼容的版本。使用npm ls命令来检查所有已安装的依赖项。

    使用兼容版本:如果你知道某个版本的腾讯云SDK与你的小程序环境兼容,那么安装这个特定版本。

    自定义模块:如果你有能力修改腾讯云SDK的源代码,可以尝试自定义一个符合小程序环境的加密模块,并替换原有的加密模块。

    联系腾讯云支持:如果以上方法都无法解决问题,建议联系腾讯云官方支持,他们可能能提供更具体的解决方案。


    以上方案没有绝对的最佳答案,根据具体情况选择最合适的方案。如果需要进一步的帮助或代码示例,请提供更多关于你的项目配置和使用的腾讯云SDK版本的信息。

    2023-09-22
    有用 1
    回复
登录 后发表内容