timecc timecc - 1 year ago 250
TypeScript Question

Webpack fails with Node FFI and Typescript - dynamic require error

In a simple Typescript program I

Node FFI with

import * as Electron from 'electron';`
import * as ffi from 'ffi';`

and then

mylib = ffi.Library('libmoi', {
'worker': [ 'string', [ 'string' ] ],
'test' : [ 'string', [] ]
} );

Linking that up via webpack yields

WARNING in ./~/bindings/bindings.js
Critical dependencies:
76:22-40 the request of a dependency is an expression
76:43-53 the request of a dependency is an expression
@ ./~/bindings/bindings.js 76:22-40 76:43-53

The problem seems to be that FFI has a dynamic
and the fix seems to be to apply
in the

This is a bit out of my reach, but an example for an Angular case is:

plugins: [
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
root('./src') // location of your src

Any idea how to do this for FFI?

Answer Source

Here is the answer: github issue comment on the Johnny-Five repo

Quoting from brodo's answer, this is what you do to stop webpack getting snarled up with "bindings" and similar:

... the webpack config looks like this:

module.exports = {
  plugins: [
    new webpack.ContextReplacementPlugin(/bindings$/, /^$/)
  externals: ["bindings"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download