module.exports “Module is not defined”

后端 未结 2 907
鱼传尺愫
鱼传尺愫 2020-12-09 02:13

So, I am using RequireJS and React, trying to load a third-party component, which has been installed with:

npm install react-autocomplete

T

2条回答
  •  -上瘾入骨i
    2020-12-09 02:53

    RequireJS cannot load CommonJS modules as-is. However, there is a minimal modification you can make to them to load them. You have to wrap them in a define call like this:

    define(function (require, exports, module) {
    
      module.exports = {
        Combobox: require('./combobox'),
        Option: require('./option')
      };
    
    });
    

    If you have a bunch of modules you need to convert, or if you are using a third-party library written in the CommonJS pattern and want to convert it as part of a build process, you can use r.js to perform the conversion for you.

提交回复
热议问题