首页 > 解决方案 > Excel JavaScript 自定义函数中的“ReferenceError:找不到变量:需要”

问题描述

我正在尝试运行需要两个第三方库的自定义函数。我将库添加到库的窗格中,如下所示:

@tensorflow/tfjs@1.5.1

@tensorflow/tfjs-node@1.4.0

sentence-tokenization@1.0.2


我收到这些错误:

{
    "error": [
        "ReferenceError: Can't find variable: exports",
        "https://unpkg.com/@tensorflow/tfjs-node@1.4.0/dist/index.js",
        32,
        30,
        {
            "message": "Can't find variable: exports",
            "line": 32,
            "column": 30,
            "sourceURL": "https://unpkg.com/@tensorflow/tfjs-node@1.4.0/dist/index.js",
            "stack": "global code@https://unpkg.com/@tensorflow/tfjs-node@1.4.0/dist/index.js:32:30"
        }
    ]
}

{
    "error": [
        "ReferenceError: Can't find variable: require",
        "https://script-lab-runner.azureedge.net/",
        38,
        17,
        {
            "message": "Can't find variable: require",
            "line": 38,
            "column": 17,
            "sourceURL": "https://script-lab-runner.azureedge.net/",
            "stack": "global code@https://script-lab-runner.azureedge.net/:38:17"
        }
    ]
}

{
    "error": [
        "ReferenceError: Can't find variable: require",
        "https://unpkg.com/sentence-tokenization@1.0.2/tokenizers.js",
        1,
        19,
        {
            "message": "Can't find variable: require",
            "line": 1,
            "column": 19,
            "sourceURL": "https://unpkg.com/sentence-tokenization@1.0.2/tokenizers.js",
            "stack": "global code@https://unpkg.com/sentence-tokenization@1.0.2/tokenizers.js:1:19"
        }
    ]
}

自定义函数的代码也抱怨需要,但我能够用这个解决它。

declare var require: any;

我在这里找到了建议,但不确定如何让它与库一起使用。

我错过了什么?

提前致谢。

标签: office-jscustom-functions-excelscriptlab

解决方案


推荐阅读