enb / enb-bemxjst

bem-xjst support for ENB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Require local module silently fails

DimitryDushkin opened this issue · comments

// make.js
requires: {
  routes: {
   commonJs: '../../server/routes/routes.js'  // path relative to index.bemhtml.js ?
  }
}

Silently fails to require local module.

I need this to have single module on backend and front-end.

@DimitryDushkin https://github.com/enb/enb-bemxjst#Подключение-сторонних-библиотек

commonJS: 'path/to/lib-name' // Путь к модулю CommonJS относительно собираемого файла

Thanks) commonJs -> commonJS

After fix I got next problem:

// some.bemhtml.js
block('some').content()(function() {
 var routes = this.require('routes');
});

Produces error:

Error: Cannot find module '../../../server/routes/routes.js'
    at s (/Users/dndushkin/ydf/az-onco-front/front/desktop.bundles/index/index.bemhtml.js:6477:164)
    at s (/Users/dndushkin/ydf/az-onco-front/front/desktop.bundles/index/index.bemhtml.js:6477:130)
    at /Users/dndushkin/ydf/az-onco-front/front/desktop.bundles/index/index.bemhtml.js:7476:21
    at Object.<anonymous> (/Users/dndushkin/ydf/az-onco-front/front/desktop.bundles/index/index.bemhtml.js:7527:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
^C⏎

It's strange cause I see routes.js code in index.bemhtml.js:

"/Users/dndushkin/ydf/az-onco-front/server/routes/routes.js":[function(require,module,exports){
var routes = { ...
};

module.exports = routes;

},{}]

@DimitryDushkin

requires: {
    lib: { commonJS: path.resolve('./lib') }
}

@miripiruni @tadatuta thx! It works!

Please mention it in docs, that path must be absolute, not relative. Currently: 'Путь к модулю CommonJS относительно собираемого файла'.