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

Dynamic require() calls produce a warning in webpack #42

Open
danieldietrich opened this issue Dec 18, 2017 · 5 comments
Open

Dynamic require() calls produce a warning in webpack #42

danieldietrich opened this issue Dec 18, 2017 · 5 comments

Comments

@danieldietrich
Copy link

My webpack builds currently produce the following warning for webpack { target: 'node' } (but not for { target: 'web' }:

WARNING in ./node_modules/bindings/bindings.js
81:22-40 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/bindings/bindings.js
 ...

This is the line that produces the warning:

b = opts.path ? require.resolve(n) : require(n)

Versions:

bindings: 1.3.0
npm: 5.5.1
node: 8.2.0
webpack: 3.10.0
babel-core: 6.26.0
babel-loader: 7.1.2
babel-plugin-transform-es3-member-expression-literals: 6.22.0
babel-plugin-transform-es3-property-literals: 6.22.0
babel-plugin-transform-object-rest-spread: 6.26.0
babel-preset-es2015: 6.24.1
@danieldietrich
Copy link
Author

danieldietrich commented Dec 18, 2017

This seems to be related to webpack/webpack-dev-server#212

Here is a suggestion on how to solve it.

@simonbland
Copy link

simonbland commented May 2, 2018

Same warning messages for me with "target": "electron-renderer" and trying to load a native node module.

A solution that worked for me is to add the following to webpack.config.js:

externals: {
  bindings: 'require("bindings")'
}

And also to copy the .node file to thebuild/ directory, as explained in Cinan's Integrate Native Node.js Modules Into an Electron App (1/2) blog post.

It would be nice to be able to configure webpack to avoid such coping though.

@joshuapinter
Copy link

I had to use something like:

const odbc = require( "electron" ).remote.require( "odbc" );

Otherwise, I got an error.

@knowroozi
Copy link

Neither of these worked for me as there were some downstream issues, but the comment here resolved it for me jsdom/jsdom#2066 (comment)

@timfish
Copy link

timfish commented Sep 26, 2018

If you want to avoid using externals, this works

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

5 participants