Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm run -s -- ndts . > lib-types.d.ts doesn't seem to do anything #99

Closed
kayvanbree opened this issue Dec 30, 2017 · 4 comments
Closed

Comments

@kayvanbree
Copy link

I'm working on Windows in WebStorm, I have an Angular 5 electron app up and running and I want to create a nodejs extension so I can use opencv in c++.

When running the npm run -s -- ndts . > lib-types.d.ts ndts doesn't generate anything inside lib-types.d.ts. Therefor TypeScript doesn't recognize lib-types as a module. Compiling seems to work as I have a build folder with my obj file.

When running the command it doesn't print anything to the console, so I can't figure out what's going wrong. Can you help me figure out what is wrong? I can provide more information, when I know what information to provide.

@jjrv
Copy link
Member

jjrv commented Dec 31, 2017

Can you share your C++ code? Is there an NBIND_CLASS block? Does calling it from plain JavaScript work?

@kayvanbree
Copy link
Author

kayvanbree commented Jan 1, 2018

Hey jjrv, all code I have can be temporarily found at https://bitbucket.org/kayvanbree/screencapture/overview. The c++ code was the following (based on the example):

#include <string>
#include <iostream>

struct Streaming {
  static void sayHello(std::string name) {
    std::cout
      << "Hello, "
      << name << "!\n";
  }
};

#include "nbind/nbind.h"

NBIND_CLASS(Streaming) {
  method(sayHello);
}

When I add the following to index.html I get an error:

<script>
      var nbind = require('nbind');
      var lib = nbind.init().lib;
      lib.Streaming.sayHello('something');

    </script>

The error is:

Uncaught Error: Module did not self-register.
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:173:20)
    at Object.Module._extensions..node (module.js:598:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:173:20)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at initNode (E:\Projects\streaming\frontend\node_modules\nbind\dist\nbind.js:141:15)
    at E:\Projects\streaming\frontend\node_modules\nbind\dist\nbind.js:115:13

Another quick question: Is it possible to get a video stream to a canvas / video through nbind?

@kayvanbree
Copy link
Author

kayvanbree commented Jan 3, 2018

So I created a fresh installation without Electron or any code, just following the tutorial from the nbind readme. TypeScript seems to be generated now, but I got another error message than before:

Uncaught TypeError: Arguments to path.resolve must be strings
    at Object.exports.resolve (webpack-internal:///../../../../path-browserify/index.js:71)
    at findCompiledModule (webpack-internal:///../../../../nbind/dist/nbind.js:70)
    at find (webpack-internal:///../../../../nbind/dist/nbind.js:93)
    at Object.init (webpack-internal:///../../../../nbind/dist/nbind.js:104)
    at eval (webpack-internal:///../../../../../src/app/app.component.ts:11)
    at Object.../../../../../src/app/app.component.ts (main.bundle.js:28)
    at __webpack_require__ (inline.bundle.js:55)
    at eval (webpack-internal:///../../../../../src/app/app.module.ts:11)
    at Object.../../../../../src/app/app.module.ts (main.bundle.js:36)
    at __webpack_require__ (inline.bundle.js:55)

Debug window

I think this should contain the path information of my compiled module. Am I right about that?

Another thing: I get multiple warnings while compiling looking like this:

WARNING in ./node_modules/nbind/dist/nbind.js
128:4-32 Critical dependency: the request of a dependency is an expression
    at CommonJsRequireContextDependency.getWarnings (E:\Projects\streaming\steampp\node_modules\webpack\lib\dependencies\ContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (E:\Projects\streaming\steampp\node_modules\webpack\lib\Compilation.js:703:24)
    at Compilation.finish (E:\Projects\streaming\steampp\node_modules\webpack\lib\Compilation.js:561:9)
    at applyPluginsParallel.err (E:\Projects\streaming\steampp\node_modules\webpack\lib\Compiler.js:502:17)
    at E:\Projects\streaming\steampp\node_modules\tapable\lib\Tapable.js:289:11
    at _addModuleChain (E:\Projects\streaming\steampp\node_modules\webpack\lib\Compilation.js:507:11)
    at processModuleDependencies.err (E:\Projects\streaming\steampp\node_modules\webpack\lib\Compilation.js:477:14)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
 @ ./node_modules/nbind/dist/nbind.js
 @ ./src/app/app.component.ts
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

@kayvanbree
Copy link
Author

@jjrv I finally figured out that I forgot to include "ndts": "ndts" to my package.json. lib-types.d.ts is now actually generated with my class and method, like this:

import { Buffer } from "nbind/dist/shim";

export class NBindBase { free?(): void }

export class Streaming extends NBindBase {
	/** static void sayHello(std::string); */
	static sayHello(p0: string): void;
}

However, when I start my application (either on localhost or as Electron application) I get the following error:

ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve '../../lib-types' in 'E:\Projects\streaming\frontend\src\app'
resolve '../../lib-types' in 'E:\Projects\streaming\frontend\src\app'
  using description file: E:\Projects\streaming\frontend\package.json (relative path: ./src/app)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: E:\Projects\streaming\frontend\package.json (relative path: ./src/app)
    using description file: E:\Projects\streaming\frontend\package.json (relative path: ./lib-types)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        E:\Projects\streaming\frontend\lib-types doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        E:\Projects\streaming\frontend\lib-types.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        E:\Projects\streaming\frontend\lib-types.js doesn't exist
      as directory
        E:\Projects\streaming\frontend\lib-types doesn't exist
[E:\Projects\streaming\frontend\lib-types]
[E:\Projects\streaming\frontend\lib-types.ts]
[E:\Projects\streaming\frontend\lib-types.js]
[E:\Projects\streaming\frontend\lib-types]
 @ ./src/app/app.component.ts 14:18-44
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

I was wondering if you might be willing to publish an example how to use nbind with TypeScript. If I get this running I will publish a repository with an Angular Electron example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants