require-handlebars-plugin icon indicating copy to clipboard operation
require-handlebars-plugin copied to clipboard

requirejs build failure

Open mduman opened this issue 11 years ago • 12 comments

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)

mduman avatar Dec 07 '14 16:12 mduman

What is your require.js configuration and directory structure?

Dremora avatar Dec 10 '14 18:12 Dremora

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
});

adamgruber avatar Jan 26 '15 14:01 adamgruber

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

morficus avatar Mar 02 '15 13:03 morficus

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

mattkime avatar Mar 17 '15 21:03 mattkime

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

luos avatar Mar 17 '15 21:03 luos

@luos i have no hbs.js file.

perhaps the hbs plugin is failing to load?

mattkime avatar Mar 17 '15 22:03 mattkime

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 avatar Mar 18 '15 15:03 mattkime

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 avatar Mar 18 '15 17:03 mattkime

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 avatar Mar 18 '15 23:03 mattkime

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);
    }
}

mattkime avatar Mar 31 '15 19:03 mattkime

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.

adamgruber avatar Apr 06 '15 00:04 adamgruber

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.

mattkime avatar Apr 06 '15 02:04 mattkime