I am trying to set up the unit testing framework for react. While doing so, the following error has occurred. I have searched all over the internet with no solution that is
The error you describe is exactly what RequireJS gives you when you have a require
call in the CommonJS form (require('modX')
) instead of the AMD form (require(['modX'], function (modX) {...})
), and the call is done without being wrapped in define
. RequireJS provides some support for using the CommonJS form, but there is a minimum of work that must be done by the developer to ensure that it works. A script that starts with this won't work:
var modX = require('modX');
// rest of the module
You get the error message you got. You need this instead:
define(function (require) {
var modX = require('modX');
// rest of the module
});
What is going on with your setup is that, as it is, Babel is transforming the ES6 modules into something that uses require
without the define
wrapper. In order to get Babel to output proper AMD modules, you need to install babel-plugin-transform-es2015-modules-amd
and add transform-es2015-modules-amd
to your list of Babel plugins. See the documentation here.