【问题标题】:Browserify not accessing node_modulesBrowserify 不访问 node_modules
【发布时间】:2016-06-28 02:24:51
【问题描述】:

我使用 Watson api 制作了一个视觉识别应用程序,其中包含运行 api 调用所需的 node_modules 文件(api 调用是从 api_request 进行的,它需要我的 node_modules 文件夹中的模块。在终端中运行后,我安装并使用 browserify 在我的 package.json 中构建一个文件,如下所示:

    "build": "browserify api_request.js -o bundle.js"

但是,当 node_modules 文件夹中的模块需要 node_modules 文件夹中的另一个模块时,bundle.js 会出错。使用符号链接时,browserify 似乎没有使用“node_modules”目录。有谁知道如何解决这个问题?

【问题讨论】:

  • 只是为了确认这是问题所在,您可以尝试用目录副本替换符号链接吗?
  • 其实我刚看到stackoverflow.com/questions/35952647/…,我想我知道那里有什么问题,所以这可能是同一个根本原因。

标签: browserify symlink ibm-watson visual-recognition


【解决方案1】:

从 (v2.0.0) 开始,您可以使用 browserify 运行 watson-developer-cloud npm 模块客户端。您现在也可以要求单独的服务。

例如,要使用 Tone Analyzer 客户端,您需要一个 js 文件(例如 app.js):

var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
var toneAnalyzer = new ToneAnalyzerV3({/* credentials */});

toneAnalyzer.tone({ text: 'Greetings from Watson Developer Cloud!' },
  function(err, tone) {
    if (err)
      console.log(err);
    else
      console.log(JSON.stringify(tone, null, 2));
});

使用browserify编译客户端js:

browserify app.js -o bundle.js"

您需要安装 browserify:

 npm install browserify -g

如果你想从v1.X 移动到v2.X,有一个migration guide

【讨论】:

    猜你喜欢
    • 2023-03-16
    • 2017-09-22
    • 2016-09-23
    • 2016-03-12
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    相关资源
    最近更新 更多