jazz-midi
jazz-midi copied to clipboard
Critical dependency: the request of a dependency is an expression
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
A better approach is to use webpack require.context(). Will you accept a PR with such fix?
This module is not required for browser applications. It looks like a similar issue was addressed in https://github.com/tuzemec/jzz-webpack-test
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?
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