jazz-soft / jazz-midi

MIDI support for Node.js and browsers
https://jazz-soft.net
19 stars 4 forks source link

Critical dependency: the request of a dependency is an expression #6

Open iva2k opened 3 years ago

iva2k commented 3 years ago

Using jzz@1.3.9 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 commented 3 years ago

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

jazz-soft commented 2 years ago

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

wookayin commented 2 years ago

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 commented 2 years ago

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