2

I made a visual recognition app using Watson api which included a node_modules file necessary to run the api call (the api call was made from api_request and it required modules in my node_modules folder. After it worked in the terminal, I installed and use browserify to build a file in my package.json like so:

    "build": "browserify api_request.js -o bundle.js"

However bundle.js gave an error when a module in the node_modules folder required another module in the node_modules folder. It doesn't seem like browserify is using 'node_modules' directory when using symlink. Does anyone know how to fix this?

bwad
  • 71
  • 3
  • 16
  • 1
    Just to confirm that's the issue, could you try replacing the symlink with a copy of the directory? – Nathan Friedly Mar 15 '16 at 18:56
  • 1
    Actually, I just saw http://stackoverflow.com/questions/35952647/watson-visual-recognition-run-error and I think I know what's the issue there, so this may be the same root cause. – Nathan Friedly Mar 15 '16 at 19:02

1 Answers1

1

Starting from (v2.0.0) you can use browserify to run the watson-developer-cloud npm module client side. You can also require individual services now.

For example, to use Tone Analyzer client side you will need a js file (e.g app.js):

var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
var toneAnalyzer = new ToneAnalyzerV3({/* credentials */});

toneAnalyzer.tone({ text: 'Greetings from Watson Developer Cloud!' },
  function(err, tone) {
    if (err)
      console.log(err);
    else
      console.log(JSON.stringify(tone, null, 2));
});

Use browserify to compile the client side js:

browserify app.js -o bundle.js"

You need to have browserify installed:

 npm install browserify -g

There is a migration guide if you want to move from v1.X to v2.X

German Attanasio
  • 22,217
  • 7
  • 47
  • 63