2017-10-06 92 views
0

我有一个关于Browserify模块用法的简单问题。让我解释;Browserify node_module用法/ Google Translate Api

正如你所知,谷歌翻译是一个免费的API是“谷歌翻译-API”在NPM。我需要在浏览器中使用它,所以我必须通过使用browserify进行转换。在这一点上,Everthing对我来说很酷。

我安装了browserify并完成了我的转换过程。它的大约300kb文件和我已经检查了所有需要的节点模块,也都进行了转换。

我的问题是,当我一直在使用它,我在控制台得到一个错误:

“未捕获的错误:无法找到模块‘../../package’”

它清楚地表明它无法找到模块:)不过我是新来使用模块等

我已经通过Browserify转换模块:

https://www.npmjs.com/package/google-translate-api

我的HTML代码:

<html> 
    <head> 
    <title>Test</title>   
    </head> 
<body> 
     <script src="test.js"></script>    
    <script> 

     translate('Ik spreek Engels', {to: 'en'}).then(res => { 
     console.log(res.text); 
     //=> I speak English 
     console.log(res.from.language.iso); 
     //=> nl 
     }).catch(err => { 
     console.error(err); 
     }); 
    </script> 

    </body> 
</html> 

我从谷歌,翻译的API模块

test.js

片段

<html> 
 
    <head> 
 
     <title>Test</title>   
 
    </head> 
 
    <body> 
 
     <script src="http://bahabilgin.com/test.js"></script>    
 
     <script> 
 
      translate('Ik spreek Engels', {to: 'en'}).then(res => { 
 
      console.log(res.text); 
 
      //=> I speak English 
 
      console.log(res.from.language.iso); 
 
      //=> nl 
 
      }).catch(err => { 
 
      console.error(err); 
 
      }); 
 
     </script>   
 
    </body> 
 
</html>
转换我的test.js文件

回答

0

我建议你使用https://unpkg.com/,它比browsify容易得多..

+0

日Thnx我的朋友让我看的.. – Sinful

+0

我抬头,但我还没有看到任何例子或使用。 – Sinful

+0

将此用作cdn网址https://unpkg.com/[email protected]/index.js –

相关问题