title: node-gyp c++ chrome extension
body: <p>i need to create chrome extension that can call c++ from js so i use <a href="https://nodejs.org/api/n-api.html" rel="nofollow noreferrer">nodeapi</a>
  and to achieve that I used the <strong>node-gyp</strong></p>
  <p><strong>package.json</strong></p>
  <pre><code>{
    &quot;name&quot;: &quot;test&quot;,
    &quot;version&quot;: &quot;0.13.0&quot;,
    &quot;description&quot;: &quot;test&quot;,
    &quot;main&quot;: &quot;./index.js&quot;,
    &quot;files&quot;: [
      &quot;index.js&quot;
    ],
    &quot;engines&quot;: {
      &quot;node&quot;: &quot;&gt;=12.0.0&quot;
    },
    &quot;scripts&quot;: {
      &quot;test&quot;: &quot;node index.js&quot;,
      &quot;build&quot;: &quot;node-gyp rebuild&quot;,
      &quot;clean&quot;: &quot;node-gyp clean&quot;,
      &quot;install&quot;: &quot;prebuild-install --runtime napi || node-gyp rebuild&quot;
    },
    &quot;dependencies&quot;: {
      &quot;bindings&quot;: &quot;^1.5.0&quot;,
      &quot;browserify&quot;: &quot;^17.0.0&quot;
      &quot;node-addon-api&quot;: &quot;^3.0.2&quot;,
      &quot;prebuild-install&quot;: &quot;^6.0.0&quot;
    },
    &quot;devDependencies&quot;: {
      &quot;babel-eslint&quot;: &quot;^10.1.0&quot;,
      &quot;chai&quot;: &quot;^4.1.2&quot;,
      &quot;chai-spies&quot;: &quot;^1.0.0&quot;,
      &quot;eslint&quot;: &quot;^6.8.0&quot;,
      &quot;eslint-plugin-import&quot;: &quot;^2.20.1&quot;,
      &quot;eslint-plugin-json&quot;: &quot;^1.2.0&quot;,
      &quot;eslint-plugin-mocha&quot;: &quot;^6.2.2&quot;,
      &quot;mocha&quot;: &quot;^5.0.4&quot;,
      &quot;node-gyp&quot;: &quot;^9.1.0&quot;,
      &quot;prebuild&quot;: &quot;^10.0.1&quot;,
      &quot;rimraf&quot;: &quot;^2.6.2&quot;
    },
    &quot;gypfile&quot;: true
  }
  </code></pre>
  <p><strong>binding.gyp</strong></p>
  <pre><code>{
    &quot;targets&quot;: [
      {
          'target_name': 'hello',
          'sources': [ 'hello.cc' ],
          'defines': [
              '_LARGEFILE_SOURCE',
              '_FILE_OFFSET_BITS=64',
              'NAPI_DISABLE_CPP_EXCEPTIONS'
          ],
          'cflags!': ['-ansi', '-fno-exceptions' ],
          'cflags_cc!': [ '-fno-exceptions' ],
          'cflags': ['-g', '-exceptions'],
          'cflags_cc': ['-g', '-exceptions'],
          'include_dirs': [
            &quot;&lt;!@(node -p \&quot;require('node-addon-api').include\&quot;)&quot;
          ],
          'dependencies': [
            &quot;&lt;!(node -p \&quot;require('node-addon-api').gyp\&quot;)&quot;
          ],
      }, 
    ]
  }
  </code></pre>
  <p><strong>hello.cc</strong></p>
  <pre><code>#include &lt;napi.h&gt;
  Napi::String Method(const Napi::CallbackInfo&amp; info) {
    Napi::Env env = info.Env();
    return Napi::String::New(env, &quot;Hello Calling From Cpp&quot;);
  }
  
  Napi::Object Init(Napi::Env env, Napi::Object exports) {
    exports.Set(Napi::String::New(env, &quot;hellocc&quot;), Napi::Function::New(env, Method));
    return exports;
  }
  
  NODE_API_MODULE(hello, Init)
  </code></pre>
  <p><strong>index.js</strong></p>
  <pre><code> 'use strict'
   var addon = require('bindings')('hello');
   function testingfromjs(){
       return addon.hellocc();
   }
  exports.testingfromjs= testingfromjs;
  </code></pre>
  <p>the problem is it works fine with commands like <code>node index.js</code>
  but it didn't work when it build as chrome extension
  i imported it as dependency and use this as required in the main.js of chrome extension but it didn't work</p>