Requirejs Confilcts With Define/require Functions
so long story short - I have a problem trying to integrate requireJS in the old project with whole bunch of legacy code that has a definition for global define function which conflicts with requireJS. Problem happens in karma/jasmine test when I load those two scripts.
karma.conf.js
files: [
<lib that has define global function insight>
...
webappJs + '/vendor/require.js',
'src/test/js/test-main.js',
...
]
test-main.js
var allTestFiles = [];
var TEST_REGEXP = /.*ng.*test\.js/i;
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(file);
}
});
var config = {
appDir : '',
baseUrl : '/base/src/main/webapp',
dir: "lib",
deps: allTestFiles,
callback: window.__karma__.start,
paths : {
// Configure alias to full paths
'angular' : 'lib/angular.min',
'angularMock' : '/base/src/test/lib/angular-mocks',
'requireLib': 'lib/require'
},
namespace: "appRequire",
shim : {
'angular' : {
deps : [],
exports : 'angular'
},
'angularMock' : {
deps : ['angular']
}
},
modules: [
{
name: "appRequire",
include: ["requireLib"],
create: true
}
]
};
require.config (config);
so supposedly now I have to include the appRequire.js file ??? but here is the thing I don't understand how the module will be created, who will create it? Should I not include require.js into list of files
The document doesn't say much about it...it just says that I'll be able to use define/require function as appRequire.define and appRequire.require after that...but what is the mechanism of that? What do I miss here? Cause currently requirejs is still complaining about code that uses the 'old' define function.
Thanks in advance to all of you who can shed some light on that!
Answer
fixed this problem manually resolving the conflict in main.js
if( typeof define !== 'undefined' ) {
myApp = {
define : define
};
define = void 0;
}
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM