[英]ReferenceError: require is not defined - browserify - generator-angular
I'm trying to use node-geocoder , which uses require
so I install browserify by sudo npm install -g browserify
, and I think I'm stuck on bundling all by browserify <some_file>.js -o src/assets/bundle.js
. 我试图使用节点地理编码器 ,它使用
require
,所以我安装browserify通过sudo npm install -g browserify
,我想我卡在捆绑的所有browserify <some_file>.js -o src/assets/bundle.js
。 I'm not sure which file I should choose, so I chose that were I want to use node-geocoder
( create.controller.js
) Finally I added <script src="bundle.js"></script>
to my index.html
But I still getting ReferenceError 我不确定我应该选择哪个文件,所以我选择了我想使用
node-geocoder
( create.controller.js
)最后我将<script src="bundle.js"></script>
到我的index.html
但我仍然得到ReferenceError
angular.js:13550 ReferenceError: require is not defined
at new CreateController
create.controller.js
(function () {
'use strict';
angular
.module('untitled')
.controller('CreateController', CreateController);
/** @ngInject */
function CreateController($http, $log) {
var NodeGeocoder = require('node-geocoder');
var options = {
provider: 'google',
httpAdapter: 'https', // Default
apiKey: 'myApiKey',
formatter: 'string'
};
var geocoder = NodeGeocoder(options);
geocoder.geocode('29 champs elysée paris')
.then(function(res) {
console.log(res);
})
.catch(function(err) {
console.log(err);
});
I use generator-angular I'm very new at JS and all these frameworks, so I hope that I posted all needed information. 我使用generator-angular我是JS和所有这些框架的新手,所以我希望我发布了所有需要的信息。
Require() isnt a valid function in client sided JavaScript. Require()不是客户端JavaScript中的有效函数。 Try using RequireJS ( http://requirejs.org/docs/download.html )
尝试使用RequireJS( http://requirejs.org/docs/download.html )
For help with RequireJS' API, http://requirejs.org/docs/api.html 有关RequireJS'API的帮助,请访问http://requirejs.org/docs/api.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.