【问题标题】:On Heroku, Error: The hook `grunt` is taking too long to load在 Heroku 上,错误:钩子 `grunt` 加载时间过长
【发布时间】:2016-10-02 13:54:37
【问题描述】:

第一次尝试将 SailsJS 应用程序部署到 Heroku 并遇到了困难。

我的应用程序在本地正常运行 (MacOS X)。

$ sails --version
0.12.3

heroku 日志

heroku logs -a myapp-webrtc
2016-06-02T16:52:45.297076+00:00 app[web.1]: 
2016-06-02T16:52:45.297142+00:00 app[web.1]:  *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
2016-06-02T16:52:45.297191+00:00 app[web.1]: 
2016-06-02T16:52:45.297277+00:00 app[web.1]:  *-> Or maybe you don't have permissions to access the `.tmp` directory?
2016-06-02T16:52:45.297383+00:00 app[web.1]:      e.g., `/app/.tmp` ?
2016-06-02T16:52:45.297434+00:00 app[web.1]: 
2016-06-02T16:52:45.297485+00:00 app[web.1]:      If you think this might be the case, try running:
2016-06-02T16:52:45.297607+00:00 app[web.1]:      sudo chown -R 58669 /app/.tmp
2016-06-02T16:52:45.297675+00:00 app[web.1]: 
2016-06-02T16:53:01.611997+00:00 app[web.1]: Error: The hook `grunt` is taking too long to load.
2016-06-02T16:53:01.612013+00:00 app[web.1]:     at Timer.listOnTimeout (timers.js:198:5) { [Error: The hook `grunt` is taking too long to load.
2016-06-02T16:53:01.612012+00:00 app[web.1]:     at tryOnTimeout (timers.js:224:11)
2016-06-02T16:53:01.612010+00:00 app[web.1]: Make sure it is triggering its `initialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher value (currently 20000)
2016-06-02T16:53:01.612011+00:00 app[web.1]:     at Timeout.tooLong [as _onTimeout] (/app/node_modules/sails/lib/app/private/loadHooks.js:85:21)
2016-06-02T16:53:01.612014+00:00 app[web.1]: Make sure it is triggering its `initialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher value (currently 20000)] code: 'E_HOOK_TIMEOUT' }
2016-06-02T16:53:02.849738+00:00 heroku[web.1]: Process exited with status 0
2016-06-02T16:53:02.872998+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-02T16:53:06.350353+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=myapp-webrtc.herokuapp.com request_id=2d8d592c-b091-4b87-b347-378498e5716c fwd="93.201.9.157" dyno= connect= service= status=503 bytes=
2016-06-02T16:53:06.921700+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myapp-webrtc.herokuapp.com request_id=df38991d-ef49-4563-a119-034aa717644a fwd="93.201.9.157" dyno= connect= service= status=503 bytes=
2016-06-02T17:15:14.982813+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-02T17:15:24.437298+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-02T17:15:28.109941+00:00 app[web.1]: 
2016-06-02T17:15:28.109962+00:00 app[web.1]: > myapp-sails-website@0.0.0 start /app
2016-06-02T17:15:28.109966+00:00 app[web.1]: 
2016-06-02T17:15:28.109965+00:00 app[web.1]: > node app.js
2016-06-02T17:15:32.969953+00:00 app[web.1]: designed for a production environment, as it will leak
2016-06-02T17:15:32.969938+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2016-06-02T17:15:32.969954+00:00 app[web.1]: memory, and will not scale past a single process.
2016-06-02T17:15:39.385511+00:00 app[web.1]: ------------------------------------------------------------------------
2016-06-02T17:15:39.385517+00:00 app[web.1]:   [Function: _cleanupCallback] ]
2016-06-02T17:15:39.385487+00:00 app[web.1]: 
2016-06-02T17:15:39.392709+00:00 app[web.1]: 
2016-06-02T17:15:39.385518+00:00 app[web.1]: Running "bower:install" (bower) task
2016-06-02T17:15:39.385518+00:00 app[web.1]: >> Cleaned target dir /app/assets/vendor
2016-06-02T17:15:39.385519+00:00 app[web.1]: ------------------------------------------------------------------------
2016-06-02T17:15:39.385516+00:00 app[web.1]: Fatal error: Path must be a string. Received [ '/tmp/0077235362b904e0706919379d9abb40/bower/fontawesome-26-IEN3KJ',
2016-06-02T17:15:39.394064+00:00 app[web.1]:  *-> Are "grunt" and related grunt task modules installed locally?  Run `npm install` if you're not sure.
2016-06-02T17:15:39.393890+00:00 app[web.1]: Troubleshooting tips:
2016-06-02T17:15:39.392884+00:00 app[web.1]: Looks like a Grunt error occurred--
2016-06-02T17:15:39.394010+00:00 app[web.1]: 
2016-06-02T17:15:39.394278+00:00 app[web.1]:  *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
2016-06-02T17:15:39.392993+00:00 app[web.1]: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)
2016-06-02T17:15:39.393169+00:00 app[web.1]: 
2016-06-02T17:15:39.393066+00:00 app[web.1]: Or if you're stuck, check out the troubleshooting tips below.
2016-06-02T17:15:39.394178+00:00 app[web.1]: 
2016-06-02T17:15:39.394816+00:00 app[web.1]:      sudo chown -R 51606 /app/.tmp
2016-06-02T17:15:39.394625+00:00 app[web.1]: 
2016-06-02T17:15:39.394892+00:00 app[web.1]: 
2016-06-02T17:15:39.394374+00:00 app[web.1]:  *-> Or maybe you don't have permissions to access the `.tmp` directory?
2016-06-02T17:15:39.394532+00:00 app[web.1]:      e.g., `/app/.tmp` ?
2016-06-02T17:15:39.394328+00:00 app[web.1]: 
2016-06-02T17:15:39.394676+00:00 app[web.1]:      If you think this might be the case, try running:
2016-06-02T17:15:52.228153+00:00 app[web.1]: Error: The hook `grunt` is taking too long to load.
2016-06-02T17:15:52.228162+00:00 app[web.1]: Make sure it is triggering its `initialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher value (currently 20000)
2016-06-02T17:15:52.228164+00:00 app[web.1]:     at Timeout.tooLong [as _onTimeout] (/app/node_modules/sails/lib/app/private/loadHooks.js:85:21)
2016-06-02T17:15:52.228165+00:00 app[web.1]:     at tryOnTimeout (timers.js:224:11)
2016-06-02T17:15:52.228165+00:00 app[web.1]:     at Timer.listOnTimeout (timers.js:198:5) { [Error: The hook `grunt` is taking too long to load.
2016-06-02T17:15:52.228167+00:00 app[web.1]: Make sure it is triggering its `initialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher value (currently 20000)] code: 'E_HOOK_TIMEOUT' }
2016-06-02T17:15:53.669743+00:00 heroku[web.1]: State changed from starting to crashed
2016-06-02T17:15:53.655028+00:00 heroku[web.1]: Process exited with status 0
2016-06-02T18:06:31.272886+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-02T18:06:36.225210+00:00 heroku[web.1]: Starting process with command `npm start`
2016-06-02T18:06:38.532682+00:00 app[web.1]: > myapp-sails-website@0.0.0 start /app
2016-06-02T18:06:38.532687+00:00 app[web.1]: > node app.js
2016-06-02T18:06:38.532667+00:00 app[web.1]: 
2016-06-02T18:06:38.532688+00:00 app[web.1]: 
2016-06-02T18:06:40.055713+00:00 app[web.1]: Warning: connect.session() MemoryStore is not
2016-06-02T18:06:40.055780+00:00 app[web.1]: memory, and will not scale past a single process.
2016-06-02T18:06:40.055777+00:00 app[web.1]: designed for a production environment, as it will leak
2016-06-02T18:06:43.891199+00:00 app[web.1]: ------------------------------------------------------------------------
2016-06-02T18:06:43.891203+00:00 app[web.1]:   [Function: _cleanupCallback] ]
2016-06-02T18:06:43.891204+00:00 app[web.1]: >> Cleaned target dir /app/assets/vendor
2016-06-02T18:06:43.891202+00:00 app[web.1]: Fatal error: Path must be a string. Received [ '/tmp/9f58527d2d49adf07e59162a077b871c/bower/bootstrap-26-nvHWyj',
2016-06-02T18:06:43.891205+00:00 app[web.1]: ------------------------------------------------------------------------
2016-06-02T18:06:43.891203+00:00 app[web.1]: Running "bower:install" (bower) task
2016-06-02T18:06:43.891391+00:00 app[web.1]: Looks like a Grunt error occurred--
2016-06-02T18:06:43.891393+00:00 app[web.1]: Please fix it, then **restart Sails** to continue running tasks (e.g. watching for changes in assets)
2016-06-02T18:06:43.891906+00:00 app[web.1]: 
2016-06-02T18:06:43.891934+00:00 app[web.1]:  *-> Are "grunt" and related grunt task modules installed locally?  Run `npm install` if you're not sure.
2016-06-02T18:06:43.891899+00:00 app[web.1]: Troubleshooting tips:
2016-06-02T18:06:43.891390+00:00 app[web.1]: 
2016-06-02T18:06:43.891433+00:00 app[web.1]: Or if you're stuck, check out the troubleshooting tips below.
2016-06-02T18:06:43.891476+00:00 app[web.1]: 
2016-06-02T18:06:43.891189+00:00 app[web.1]: 
2016-06-02T18:06:43.892016+00:00 app[web.1]:  *-> You might have a malformed LESS, SASS, CoffeeScript file, etc.
2016-06-02T18:06:43.891973+00:00 app[web.1]: 
2016-06-02T18:06:43.892187+00:00 app[web.1]: 
2016-06-02T18:06:43.892084+00:00 app[web.1]: 
2016-06-02T18:06:43.892304+00:00 app[web.1]: 
2016-06-02T18:06:43.892265+00:00 app[web.1]:      sudo chown -R 59724 /app/.tmp
2016-06-02T18:06:43.892088+00:00 app[web.1]:  *-> Or maybe you don't have permissions to access the `.tmp` directory?
2016-06-02T18:06:43.892144+00:00 app[web.1]:      e.g., `/app/.tmp` ?
2016-06-02T18:06:43.892259+00:00 app[web.1]:      If you think this might be the case, try running:
2016-06-02T18:06:59.974471+00:00 app[web.1]:     at Timeout.tooLong [as _onTimeout] (/app/node_modules/sails/lib/app/private/loadHooks.js:85:21)
2016-06-02T18:06:59.974435+00:00 app[web.1]: Error: The hook `grunt` is taking too long to load.
2016-06-02T18:06:59.974469+00:00 app[web.1]: Make sure it is triggering its `initialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher value (currently 20000)
2016-06-02T18:06:59.974474+00:00 app[web.1]: Make sure it is triggering its `initialize()` callback, or else set `sails.config.grunt._hookTimeout to a higher value (currently 20000)] code: 'E_HOOK_TIMEOUT' }
2016-06-02T18:06:59.974473+00:00 app[web.1]:     at Timer.listOnTimeout (timers.js:198:5) { [Error: The hook `grunt` is taking too long to load.
2016-06-02T18:06:59.974472+00:00 app[web.1]:     at tryOnTimeout (timers.js:224:11)
2016-06-02T18:07:00.662956+00:00 heroku[web.1]: Process exited with status 0
2016-06-02T18:07:00.697875+00:00 heroku[web.1]: State changed from starting to crashed

任何指针?

我的 bower.json

$ more bower.json
{
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "dependencies": {
    "bootstrap": "~3.3.6",
    "fontawesome": "~4.6.3"
  },
  "exportsOverride": {
    "bootstrap": {
      "js": "dist/js/*.min.*",
      "less": "less/"
    },
    "fontawesome": {
      "less": "less/",
      "fonts": "fonts/"
    },
    "jquery": {
      ".": "dist/*.min.*"
    }
  },
  "name": "sails-website",
  "version": "0.1.0",
  "author": "joel",
  "private": true
}

咕噜构建

$ heroku run  node_modules/.bin/grunt build
Running node_modules/.bin/grunt build on ⬢myapp-webrtc... up, run.3290
Running "bower:install" (bower) task
>> Cleaned target dir /app/assets/vendor
Fatal error: Path must be a string. Received [ '/tmp/3fc3abe767162452221ee2ffa49efa28/bower/fontawesome-3-h46jhs',
  [Function: _cleanupCallback] ]

Heroku 上的 Bower 版本

$ heroku run bower --version
Running bower --version on ⬢ myapp... up, run.8617
1.2.8

【问题讨论】:

    标签: heroku gruntjs sails.js bower


    【解决方案1】:

    Getting the error "Arguments to path.join must be strings"? Clear cache and update to Bower 1.3.8.

    构建包

    不确定这个是强制性的,但既然我有它

    $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs#v90
    

    清理凉亭缓存

    $ heroku run bower cache clean
    

    package.json

    {
      "scripts": {
        "postinstall": "bower install; grunt build",    <==== ADDED THIS LINE
        "debug": "node debug app.js",
        "start": "node app.js"
      },
      "dependencies": {
        "bower": "1.3.8",     <==== ADDED THIS TO MAKE SURE TO USE VERSION 1.3.8
        "connect-redis": "^3.0.2",
        "ejs": "2.3.4",
        "grunt": "0.4.5",
        "grunt-bower": "^0.21.2",
        "grunt-bower-task": "^0.3.4",
        "grunt-contrib-clean": "0.6.0",
        "grunt-contrib-coffee": "0.13.0",
        "grunt-contrib-concat": "0.5.1",
        "grunt-contrib-copy": "0.5.0",
        "grunt-contrib-cssmin": "0.9.0",
        "grunt-contrib-jst": "0.6.0",
        "grunt-contrib-less": "1.1.0",
        "grunt-contrib-uglify": "0.7.0",
        "grunt-contrib-watch": "0.5.3",
        "grunt-sails-linker": "~0.10.1",
        "grunt-sync": "0.2.4",
        "include-all": "~0.1.6",
        "rc": "1.0.1",
        "sails": "~0.12.3",
        "sails-disk": "~0.10.9"
      },
      "name": "myapp-sails-website",
      "private": true,
      "version": "0.0.0",
      "description": "a Sails application",
      "keywords": [],
      "main": "app.js",
      "repository": {
        "type": "git",
        "url": "git://github.com/joel/myapp.git"
      },
      "author": "joel",
      "license": ""
    }
    

    然后git push heroku master

    $ heroku run bower --version
    Running bower --version on ⬢ myapp... up, run.3350
    1.3.8
    

    这解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2017-06-12
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      • 2012-08-23
      • 2016-06-20
      • 2016-02-17
      相关资源
      最近更新 更多