TypeError:翻译不是构造函数

时间:2018-08-25 18:23:57

标签: node.js google-translate

这是将英语翻译为ru的代码

       - job_name: 'kubernetes-service-endpoints'
+        honor_labels: true

         kubernetes_sd_configs:
           - role: endpoints

         relabel_configs:
           - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
             action: keep
             regex: true
           - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
             action: replace
             target_label: __scheme__
             regex: (https?)
           - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
             action: replace
             target_label: __metrics_path__
             regex: (.+)
           - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
             action: replace
             target_label: __address__
             regex: ([^:]+)(?::\d+)?;(\d+)
             replacement: $1:$2
           - action: labelmap
             regex: __meta_kubernetes_service_label_(.+)
           - source_labels: [__meta_kubernetes_namespace]
             action: replace
-            target_label: kubernetes_namespace
+            target_label: namespace
           - source_labels: [__meta_kubernetes_service_name]
             action: replace
-            target_label: kubernetes_name
+            target_label: service
+          - source_labels: [__meta_kubernetes_pod_name]
+            action: replace
+            target_label: pod
+          - source_labels: [__meta_kubernetes_pod_node_name]
+            action: replace
+            target_label: node

TypeError:翻译不是构造函数错误,如果我们将其声明为函数,则错误会清除

但是下一个错误出现在const声明中

3 个答案:

答案 0 :(得分:3)

尝试如下所示的.v2版本

const {Translate} = require('@google-cloud/translate').v2;

答案 1 :(得分:1)

const {Translate} = require('@google-cloud/translate');

导致Translate未定义。

the documentation指出,Translate@google-cloud/translate模块导出:

const Translate = require('@google-cloud/translate');

答案 2 :(得分:1)

var Translate = require('@ google-cloud / translate');

var translation = new Translate.Translate({     projectId:projectId,   });