LoginSignup
0
0

More than 5 years have passed since last update.

browserifyのrequireに指定できるのは文字列リテラルだけ

Last updated at Posted at 2018-04-23

以下のいずれも実行時に「Uncaught Error: Cannot find module」が発生する

var validPath = './util';
var util = require(validPath);
var util = require('./' + 'util');

上記のように書くとbrowserify結果ファイルの例の

},{"./aaa":9,"./bbb":15,"./util":49}],4:[function(require,module,exports){

みたいなやつが

},{"./aaa":9,"./bbb":15}],4:[function(require,module,exports){

となってしまう

以下によればそういうもんみたいなのであきらめるしかない
https://github.com/browserify/browserify/issues/664#issuecomment-35615649

browserify doesn't work with conditional requires and can't be made to work with arbitrary dynamic requires without solving the halting problem first. Do something different instead. This is a dead end.

あきらめられなかったので続き → browserify前にrequireのパスを正規表現で置換

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0