在Angular 5和TypeScript中使用nbind

我正尝试使用nbind在Angular网站中轻松创建一个C ++ NodeJS模块。 我在Webstorm中创建了一个新的Angular CLI项目,并在https://github.com/charto/nbind上跟着教程。 一切正在建立,我的lib-types.dt文件正在生成:

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

export class NBindBase { free?(): void }

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

我像这样在我的AppComponent中导入库:

import { Component } from '@angular/core';
import * as nbind from 'nbind';
import * as LibTypes from './../lib-types';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';

  sayHello() {
    const lib = nbind.init<typeof LibTypes>().lib;
    lib.Greeter.sayHello('aaaaaaaaaaaaaah');
  }
}

我添加了一个按钮(click)=>“sayHello()”,它应该调用库。 运行应用程序时,我得到了多个警告(依赖关系的请求是一个表达式):

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:Projectsstreamingasdfstreamppnode_moduleswebpacklibdependenciesContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:703:24)
    at Compilation.finish (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:561:9)
    at applyPluginsParallel.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompiler.js:502:17)
    at E:Projectsstreamingasdfstreamppnode_modulestapablelibTapable.js:289:11
    at _addModuleChain (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:507:11)
    at processModuleDependencies.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.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

WARNING in ./node_modules/nbind/dist/nbind.js
141:14-42 Critical dependency: the request of a dependency is an expression
    at CommonJsRequireContextDependency.getWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibdependenciesContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:703:24)
    at Compilation.finish (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:561:9)
    at applyPluginsParallel.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompiler.js:502:17)
    at E:Projectsstreamingasdfstreamppnode_modulestapablelibTapable.js:289:11
    at _addModuleChain (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:507:11)
    at processModuleDependencies.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.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

WARNING in ./node_modules/nbind/dist/nbind.js
53:28-53 Critical dependency: the request of a dependency is an expression
    at RequireResolveContextDependency.getWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibdependenciesContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:703:24)
    at Compilation.finish (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:561:9)
    at applyPluginsParallel.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompiler.js:502:17)
    at E:Projectsstreamingasdfstreamppnode_modulestapablelibTapable.js:289:11
    at _addModuleChain (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:507:11)
    at processModuleDependencies.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.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

WARNING in ./node_modules/nbind/dist/nbind.js
72:28-57 Critical dependency: the request of a dependency is an expression
    at RequireResolveContextDependency.getWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibdependenciesContextDependency.js:39:18)
    at Compilation.reportDependencyErrorsAndWarnings (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:703:24)
    at Compilation.finish (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:561:9)
    at applyPluginsParallel.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompiler.js:502:17)
    at E:Projectsstreamingasdfstreamppnode_modulestapablelibTapable.js:289:11
    at _addModuleChain (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.js:507:11)
    at processModuleDependencies.err (E:Projectsstreamingasdfstreamppnode_moduleswebpacklibCompilation.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

另外,当我点击按钮,我得到以下错误:

ERROR TypeError: Arguments to path.resolve must be strings
    at Object.exports.resolve (index.js:71)
    at findCompiledModule (nbind.js:70)
    at find (nbind.js:93)
    at Object.init (nbind.js:104)
    at AppComponent.sayHello (app.component.ts:14)
    at Object.eval [as handleEvent] (AppComponent.html:1)
    at handleEvent (core.js:13530)
    at callWithDebugContext (core.js:15039)
    at Object.debugHandleEvent [as handleEvent] (core.js:14626)
    at dispatchEvent (core.js:9945)

这是nbind中的错误,还是我以错误的方式导入我的库?

当前的代码可以在https://github.com/kayvanbree/angular-nbind-boilerplate找到。



问题在于你在你的角度应用程序中导入nbind,并且nbind需要node或者python来运行nbind。

您应该在您的节点(服务器端)应用程序中导入,而不是在您的角度(客户端应用程序)上导入。

链接地址: http://www.djcxy.com/p/41207.html

上一篇: Using nbind with Angular 5 and TypeScript

下一篇: Yii2: How to force using fallback MessageFormatter method?