SlexAxton / require-handlebars-plugin

A plugin for handlebars in require.js (both in dev and build)
804 stars 202 forks source link

requirejs build failure #216

Open mduman opened 9 years ago

mduman commented 9 years ago

Hello,

i could not manage to build my app with r.js. (it works fine witjhout build)

versions: "requirejs": "~2.1.15", "handlebars": "~2.0.0", "require-handlebars-plugin": "~0.11.1"

Could you help about the below error message please?

[18:19:08] Error: Error: ENOENT, no such file or directory 'B:_prod\app\hbs.js'

In module tree: modules/book modules/book/views

at Object.fs.openSync (fs.js:438:18)

at B:\node_modules\requirejs\bin\r.js:25976:19
at B:\node_modules\requirejs\bin\r.js:3005:39
at B:\node_modules\requirejs\bin\r.js:2945:25
at Function.prim.nextTick (B:\node_modules\requirejs\bin\r.js:25806:9)
at Object.p.errback (B:\node_modules\requirejs\bin\r.js:2944:26)
at Object.p.callback (B:\node_modules\requirejs\bin\r.js:2930:23)
at Object.p.promise.then (B:\node_modules\requirejs\bin\r.js:2984:23)
at build (B:\node_modules\requirejs\bin\r.js:25933:12)
at runBuild (B:\node_modules\requirejs\bin\r.js:27859:17)
at Object.context.execCb (B:\node_modules\requirejs\bin\r.js:1898:33)
Dremora commented 9 years ago

What is your require.js configuration and directory structure?

adamgruber commented 9 years ago

I'm having a similar issue trying to build my app. Getting this error when trying to build: Error: Error: ENOENT, no such file or directory '/Users/adamgruber/Sites/agg/dist/hbs.js

RequireJS Config:

/*global requirejs */
requirejs.config({
  baseUrl: '',
  paths: {
    jquery:              ['../bower_components/jquery/dist/jquery', '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery'],
    backbone:            '../bower_components/backbone/backbone',
    underscore:          '../bower_components/underscore/underscore',
    slick:               '../bower_components/slick.js/slick/slick',
    velocity:            '../bower_components/velocity/velocity',
    hbs:                 '../bower_components/require-handlebars-plugin/hbs',
    handlebars:          '../bower_components/require-handlebars-plugin/hbs/handlebars',
    PortfolioView:       'js/views/PortfolioView',
    ProjectView:         'js/views/ProjectView',
    PortfolioCollection: 'js/models/PortfolioCollection',
    ProjectModel:        'js/models/ProjectModel'
  },
  shim: {
    slick:    ['jquery'],
    velocity: ['jquery']
  },
  hbs: {
    helpers:           false,
    i18n:              false,
    templateExtension: 'mu',
    partialsUrl:       'views/templates'
  }
});

Directory Structure (trimmed a bit for clarity):

.
├── app.js
├── bin
├── bower_components/
│   ├── backbone/
│   ├── bootstrap/
│   ├── fontawesome/
│   ├── jquery/
│   ├── require-handlebars-plugin/
│   ├── requirejs/
│   ├── slick.js/
│   ├── underscore/
│   └── velocity/
├── node_modules/
├── build.js
├── dist/
├── public/
│   ├── favicon.ico
│   ├── fonts/
│   ├── images/
│   ├── js/
│   │   ├── home.js
│   │   ├── main.js
│   │   ├── models
│   │   │   ├── PortfolioCollection.js
│   │   │   └── ProjectModel.js
│   │   ├── modernizr.min.js
│   │   ├── requirejs.conf.js
│   │   └── views
│   │       ├── PortfolioView.js
│   │       └── ProjectView.js
│   └── stylesheets/
├── router.js
├── routes/
├── source/
├── source-images/
└── views/
    ├── 404.mu
    ├── error.mu
    ├── index.mu
    ├── layouts/
    │   └── default.mu
    ├── partials/
    │   ├── _about.mu
    │   ├── _footer.mu
    │   ├── _intro.mu
    │   ├── _navbar.mu
    │   ├── _portfolio.mu
    │   └── _resume.mu
    └── templates/
        └── _project.mu

And here's the file where I'm using the hbs plugin:

define([
  'backbone',
  'hbs!templates/_project',
  'jquery'
], function(Backbone, ProjectTemplate, $) {
// more code here
});
morficus commented 9 years ago

Running in to the same issue. At first blush it seems like an issue with having a file called hbs.js and a directory called hbs at the same level.

@adamgruber did you ever find a solution?

edit: using require-handlebars-plugin 0.11.2 require.js 2.1.15 and grunt-requirejs 0.4.2

mattkime commented 9 years ago

i'm seeing something similar. using grunt-contrib-requirejs 0.4.4

luos commented 9 years ago

You have to rename hbs.js to something else. That fixed for me.

mattkime commented 9 years ago

@luos i have no hbs.js file.

perhaps the hbs plugin is failing to load?

mattkime commented 9 years ago

it seems the hbs.js file was not being copied although the hbs dir was. i'm not familiar enough with requirejs to say why this would occur.

mattkime commented 9 years ago

this issue appears to be resolved in a newer version of requirejs. i saw the problem under 2.1.11 but its gone under 2.1.16

@mduman can you confirm?

mattkime commented 9 years ago

i lied. its still there.

i think the problem is that there is both an hsb dir and hbs file. the problem is only shown when the content for this project is outside your base dir

mattkime commented 9 years ago

my bower content is not within my requirejs base directory, therefore the build fails due to the following lines of code.

the fix - don't have hbs.js and the hbs dir.

//Skip empty: paths
if (srcPath !== 'empty:') {
    //If the srcPath is a directory, copy the whole directory.
    if (file.exists(srcPath) && file.isDirectory(srcPath)) {
        //Copy files to build area. Copy all files (the /\w/ regexp)
        file.copyDir(srcPath, destPath, /\w/, true);
    } else {
        //Try a .js extension
        srcPath += '.js';
        destPath += '.js';
        file.copyFile(srcPath, destPath);
    }
}
adamgruber commented 9 years ago

I took another look at this but still no luck. Definitely seems to be an issue with the mix of hbs.js and the hbs directory. At this point I'm looking into precompiling templates using a gulp task and requiring that file.

mattkime commented 9 years ago

after some further investigation i think the best solution is to make hbs.js rely on externally available modules rather than attempt to supply its own. it would also be good to reduce the number of dependencies - the i18n bits should be removed and reliance on underscore could be refactored out. Handlebars would still need to be supplied.