W
W
Worddoc2017-06-13 19:26:20
JavaScript
Worddoc, 2017-06-13 19:26:20

3rd party local RequireJS library not included?

Hello.
There is a config file for require js with the following code:

requirejs.config({
  paths: {
    "value": 'modules/index/value',
    "dom": 'modules/index/dom',
    "app" : "modules/index/app/app",
    "init": 'modules/index/init'
  },
  shim: {
    "libs.min": {
      exports: 'libs',
    }
  }
});

require(['value', 'dom', 'app', 'init'],function(value, dom, app, init){
  init.initJs();
});

Problem in including libs.min.js
There is a module that depends on libs.min.js(libs)
define(['value', 'dom', 'libs'], function(value, dom, libs) {
  var app = {
    progressBarStart: function() {
      NProgress.configure({ ease: 'ease', speed: 900 });
      NProgress.start();
    },
    progressBarDone: function() {
      NProgress.done();
    }
  };
  return app;
});

But for some reason, it displays an error in the console: Uncaught Error: Script error for "libs", needed by: app
I've been fighting for an hour now, I can't figure out what's wrong. If you include this libs.min.js file manually via script, everything works. Help, how to correctly connect a third-party file with libraries and correctly register a dependency for a damn module?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2017-06-13
@sergiks

You need the opposite: file name (without .js) - exports: module name:

shim: {
    "libs.min": {
      exports: 'libs',
    }
  }

N
Nikolai Shabalin, 2017-06-14
@nikolayshabalin

Tried like this?

require.config({
  paths: {
    libs: 'путь/до/libs.min' - обязательно без .js
  },
  shim: {
    libs: {
      exports: 'libs',
      deps: ['jquery']
    }
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question