收藏
回答

不支持npm模块nodejieba

框架类型 问题类型 终端类型 AppID 环境ID 基础库版本
小程序 Bug 工具 wx6f73ef27fe205406 cdfishdev 2.12.3

复现错误过程如下。

  1. 新建一个云函数test, index.js代码如下:

// 云函数入口文件

const cloud = require('wx-server-sdk')

cloud.init()

var nodejieba = require("nodejieba")

// 云函数入口函数

exports.main = async (event, context) => {

  var result = nodejieba.cut("南京市长江大桥")

  console.log(result)

}

2. 命令行下,切换到test目录,执行命令:npm install nodejieba

npm安装成功,日志如下:

..\cloudfunctions\test>npm install nodejieba

> nodejieba@2.5.2 install ..\cloudfunctions\test\node_modules\nodejieba

> node-pre-gyp install --fallback-to-build

[nodejieba] Success: "..\cloudfunctions\test\node_modules\nodejieba\build\Release\nodejieba.node" is installed via remote

npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN test@1.0.0 No description

npm WARN test@1.0.0 No repository field.

+ nodejieba@2.5.2

added 58 packages from 96 contributors and audited 58 packages in 74.521s

3 packages are looking for funding

  run `npm fund` for details

found 0 vulnerabilities

3.在开发工具中点击“上传并部署:云端安装依赖”

4.执行云函数test

5.此时报错,找不到模块nodejieba:

{"errorCode":-1,"errorMessage":"Runtime.ImportModuleError: Error: Cannot find module '/var/user/node_modules/nodejieba/build/Release/nodejieba.node'\n    at Object.module.exports.load (/var/runtime/node10/UserFunction.js:35:13)\n    at Runtime.handleOnce (/var/runtime/node10/Runtime.engine.js:97:38)\n    at Timeout.setTimeout [as _onTimeout] (/var/runtime/node10/Runtime.engine.js:54:12)\n    at ontimeout (timers.js:436:11)\n    at tryOnTimeout (timers.js:300:5)\n    at listOnTimeout (timers.js:263:5)\n    at Timer.processTimers (timers.js:223:10)","statusCode":443}

请问如何才能让云函数支持npm模块nodejieba呢?

最后一次编辑于  2021-06-04
回答关注问题邀请回答
收藏

2 个回答

  • hi几乎
    hi几乎
    2021-09-03

    最后解决了吗?怎么解决的?

    2021-09-03
    有用
    回复 1
    • 韩永武
      韩永武
      2021-09-16
      没解决,仍然在研究中。你也碰到这个问题了吗,有什么进展吗?
      2021-09-16
      回复
  • 老张
    老张
    2021-06-04

    谢邀。

    jieba需要重新编译,云端安装依赖可能行不通。

    试试在本地安装依赖,再整体上传部署。如果这也不行,那就没办法了。

    2021-06-04
    有用
    回复
登录 后发表内容