0

How to import/inject npm module/package bundled with browserify into AngularJS module?

angular.module('name', ['packagename']) 

&

angular.module('name', [require('packagename')]) 

Both gives error saying module not found. But it is there in bundle.js(bundle created by browserify).

1
  • This is correct.. angular.module('name', ['packagename']) However, I am not sure your bundler is actually adding it to the bundle Commented May 17, 2020 at 5:14

1 Answer 1

0

Looks like you went to wrong way.

Browserify is a tool for compiling node-flavored commonjs modules for the browser.

There is no reason to put Browserify inside Angularjs, AngularjS is a client.

It is like to put react native babel or webpack.


About angular.module('name', ['packagename'])

To import any module to your project, check that the module has:

angular.module('packagename', ['ng']). ... 

For example https://cdn.rawgit.com/angular-translate/bower-angular-translate/2.5.0/angular-translate.js

has angular.module('pascalprecht.translate', ['ng']).run(/* ... */)

Generally, you can find in DOCs that the module supports Angularjs.

Sign up to request clarification or add additional context in comments.

4 Comments

There are some packages used having 'module.exports' in the project which are usually used in NodeJs. That's why browserify is used.
There are some packages used having 'module.exports' in the project which are usually used in NodeJs. That's why browserify is used.
@Anuj, well, NodeJs runs on backend, it is not related to the client that runs statics + JS on client-side. You try to integrate in client something that manipulates with code like webpack
maybe this one will give you some insight: stackoverflow.com/questions/7576001/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.