jazz-midi icon indicating copy to clipboard operation
jazz-midi copied to clipboard

Critical dependency: the request of a dependency is an expression

Open iva2k opened this issue 3 years ago • 4 comments

Using [email protected] package (which has jazz-midi package as a dependency) in a React app (create-react-app), gets this warning:

./node_modules/jazz-midi/index.js
Critical dependency: the request of a dependency is an expression

The problem is any CI flow treats warnings as errors and chokes on it.

Looking into ./node_modules/jazz-midi/index.js:

var path='./bin/';
var v=process.versions.node.split('.');
if (v[0]<=10) path+='10_15/';
else if (v[0]<=11) path+='11_15/';
if(process.platform=="win32"&&process.arch=="ia32") path+='win32/jazz';
else if(process.platform=="win32"&&process.arch=="x64") path+='win64/jazz';
else if(process.platform=="darwin"&&process.arch=="x64") path+='macos64/jazz';
else if(process.platform=="linux"&&process.arch=="x64") path+='linux64/jazz';
else if(process.platform=="linux"&&process.arch=="arm") path+='linuxa7/jazz';
module.exports=require(path);
module.exports.package=require(__dirname + '/package.json');

... which has a dynamic require().

Webpack docs explain it here: https://webpack.js.org/guides/dependency-management/#require-with-expression

iva2k avatar Sep 19 '21 15:09 iva2k

A better approach is to use webpack require.context(). Will you accept a PR with such fix?

iva2k avatar Sep 19 '21 20:09 iva2k

This module is not required for browser applications. It looks like a similar issue was addressed in https://github.com/tuzemec/jzz-webpack-test

jazz-soft avatar Nov 22 '21 04:11 jazz-soft

Electron applications that have webpack configured will be blocked by this. (For example, I was starting off from the boilerplate https://github.com/electron-react-boilerplate) Can we have this fixed?

wookayin avatar Nov 22 '21 18:11 wookayin

Although being a hack, I found this works well with webpack:

const require_dynamic = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
module.exports = require_dynamic(path);
module.exports.package = require_dynamic(__dirname + '/package.json');

Ref: https://stackoverflow.com/questions/42797313/webpack-dynamic-module-loader-by-require

wookayin avatar Nov 22 '21 19:11 wookayin