2014-09-18 229 views
0

我嘗試將我的應用部署到heroku。一切似乎都起作用,節點軟件包已經安裝完畢,但是隨後的grunt無法解析'require'('angular')'。使用heroku-buildpack-nodejs-grunt推送到heroku時,grunt-browserify失敗

我懷疑變換的東西是失敗的,因此角度的路徑是未知的?

還是我需要添加角度專門到package.json?我很困惑,它在本地工作。

Running "browserify:dist" (browserify) task 
>> Error: ENOENT, open '/tmp/build_001656dd-4d72-40f4-b89a-b6bb75190d23/bower_components/angular/angular.js' while resolving "angular" from file /tmp/build_001656dd-4d72-40f4-b89a-b6bb75190d23/sections/_default/angular-app.js 
Warning: Error running grunt-browserify. Use --force to continue. 

Aborted due to warnings. 

!  Push rejected, failed to compile Node.js app 

我gruntfile:

/* jslint node: true */ 
'use strict'; 
module.exports = function (grunt) { 

    var transformify = require('transformify'); 
    var requires = require('./sections/_default/browser-requires.js')(); 


    var addRequires = transformify(function (x) { 
    return x.replace('/* modules browserify */', requires); 
    }); 
    // Project configuration. 
    grunt.initConfig({ 
    pkg  : grunt.file.readJSON('package.json'), 
    jshint : { 
     all  : [ 'Gruntfile.js', 'index.js', 'sections/**/*.js' ] 
    }, 
    browserify: { 
     dist: { 
     files: { 
      'static/js/app.js': ['sections/_default/angular-app.js'] 
     }, 
     options: { 
      transform: [ addRequires, 'browserify-shim'] 
     } 
     } 
    }, 
    uglify : { 
     target : { 
     files : { 'static/js/app.min.js' : 'static/js/app.js' } 
     }, 
     options: { 
     mangle: false 
     } 
    }, 
    clean : [ 'static/js/app.js' ] 
    }); 

    grunt.loadNpmTasks('grunt-browserify'); 
    grunt.loadNpmTasks('grunt-contrib-jshint'); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    grunt.loadNpmTasks('grunt-contrib-clean'); 


    // Default task(s). 
    grunt.registerTask('default', [ 
     'jshint', 
     'browserify', 
     'uglify', 
     'clean' 
    ] 
); 

    grunt.registerTask('heroku', [ 
     'jshint', 
     'browserify', 
     'uglify', 
     'clean' 
    ] 
); 

}; 

下面是我的package.json:

{ 
    "name": "developdavid", 
    "version": "0.0.0-7", 
    "main": "index.js", 
    "dependencies": { 
    "express": "~3.2.6", 
    "jade": "~0.31.2", 
    "di": "0.0.1", 
    "transformify": "~0.1.2", 
    "express-less": "0.0.2", 
    "browserify": "~3.28.1", 
    "browserify-shim": "^3.3.1", 
    "mongodb": "*", 
    "monk": "*", 
    "grunt": "~0.4.2", 
    "grunt-contrib-jshint": "~0.6.3", 
    "grunt-browserify": "^1.3.1", 
    "grunt-contrib-uglify": "^0.4.0", 
    "grunt-contrib-clean": "^0.5.0" 
    }, 
    "scripts": { 
    "test": "grunt", 
    "start": "node index.js" 
    }, 
    "browser": { 
    "jquery": "./bower_components/jquery/dist/jquery.js", 
    "angular": "./bower_components/angular/angular.js", 
    "bootstrap": "./bower_components/bootstrap/dist/js/bootstrap.js", 
    "angular-resource": "./bower_components/angular-resource/angular-resource.js", 
    "angular-route": "./bower_components/angular-route/angular-route.js", 
    "angular-bootstrap": "./bower_components/angular-bootstrap/ui-bootstrap-tpls.js", 
    "angular-animate": "./bower_components/angular-animate/angular-animate.js", 
    "angular-sanitize": "./bower_components/textAngular/src/textAngular-sanitize.js", 
    "text-angular-setup": "./bower_components/textAngular/src/textAngularSetup.js", 
    "text-angular": "./bower_components/textAngular/src/textAngular.js" 
    }, 
    "browserify-shim": { 
    "jquery": "$", 
    "angular": { 
     "exports": "angular", 
     "depends": [ 
     "jquery:$" 
     ] 
    }, 
    "text-angular-setup": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "text-angular": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "angular-sanitize": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "angular-bootstrap": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "angular-animate": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "angular-resource": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "angular-route": { 
     "depends": [ 
     "angular:angular" 
     ] 
    }, 
    "bootstrap": { 
     "depends": [ 
     "jquery:$" 
     ] 
    } 
    }, 
    "devDependencies": { 
    "grunt": "~0.4.2", 
    "grunt-contrib-jshint": "~0.6.3", 
    "grunt-browserify": "^1.3.1", 
    "grunt-contrib-uglify": "^0.4.0", 
    "grunt-contrib-clean": "^0.5.0" 
    }, 
    "subdomain": "developDavid", 
    "engines": { 
    "node": "0.10.x" 
    } 
} 

也是我的 '瀏覽器的要求' 使用的咕嚕文件:

/* jslint node: true */ 
'use strict'; 
var fs   = require('fs'); 

module.exports = function() { 
    var requires = []; 
    fs.readdirSync('./sections/').forEach(function (file) { 
    var fullpath = './sections/' + file, 
     isDirectory = fs.lstatSync(fullpath).isDirectory(); 
    if (isDirectory && file !== '_default') { 
     var dir = file; 
     fs.readdirSync('./sections/' + dir).forEach(function (file) { 
     if (/.*\.browser.js$/.test(file)) { 
      requires.push('injector.invoke(require(\'../' + dir + '/' + file + '\'));'); 
     } 
     }); 
    } 
    }); 
    return requires.join(''); 
}; 

回答

0

醜陋修正:

剛添加bower_components到提交,然後在heroku上找到所有文件。也許他們將涼亭組件安裝在不同的文件夾或其他東西... 在這種情況下,我應該有兩個,現在我猜。