我在使用webpack构建我的Node应用程序时遇到问题

时间:2018-11-16 10:15:09

标签: javascript node.js webpack

让我描述一下我的问题。我已经用ES6开发了一个Node.js应用程序,它是一个REST API,使用了多个Node模块,尤其是来自google-cloud的Node模块,因为我正在使用Google Cloud Vision和Translate API。

直到现在都没有问题,一切都按预期运行,但是当我想在Windows Server上将其作为服务运行时,出现了问题。我找到了一种使用Node模块“ node-windows”的方法here

我像该帖子中那样制作了服务脚本,并且该服务已安装并显示在Windows服务列表中,但是当我单击启动时,它立即停止。

经过分析,我记得我正在使用ES6,该ES6需要转换为ES5才能像标准Node脚本一样工作,所以我认为使用webpack构建整个应用程序可以为我解决问题,但不完全是,我得到了我用webpack生成的bundle.js没有任何错误(只是一些警告),然后当我尝试使用node ./bundle.js运行它时,它返回了诸如以下的错误:

Error: The include '/protos/google/cloud/vision/v1/image_annotator.proto' was not found.

尽管我在Webpack配置文件中制定了规则以支持.proto文件。

这是我的 webpack.config.js

module.exports = {
  target: "node",
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.json$/,
        exclude: /node_modules/,
        use: {
          loader: "json-loader"
        }
      },
      {
      test: /\.proto$/,
          use: {
            loader: "pbf-loader"
          }
      },
      {
        test: /\.html$/,
        use: {
          loader: "html-loader"
        }
      }
    ]
  }
};

在这个级别上,我不知道如何将那些google-cloud .proto文件集成到我的bundel.js中,有人可以指导我吗?谢谢。

这是@ google-cloud模块中来自grpc.js的代码,用于尝试解析.proto文件路径:

GoogleProtoFilesRoot.prototype.resolvePath = function (originPath, includePath) {
        originPath = path.normalize(originPath);
        includePath = path.normalize(includePath);
        // Fully qualified paths don't need to be resolved.
        if (path.isAbsolute(includePath)) {
            if (!fs.existsSync(includePath)) {
                throw new Error('The include `' + includePath + '` was not found.');
            }
            return includePath;
        }
        if (COMMON_PROTO_FILES.indexOf(includePath) > -1) {
            return path.join(googleProtoFilesDir, includePath);
        }
        return GoogleProtoFilesRoot._findIncludePath(originPath, includePath);
    };

0 个答案:

没有答案
相关问题