【问题标题】:Deploying unmodified reveal.js to Heroku将未修改的reveal.js部署到Heroku
【发布时间】:2017-12-31 22:38:40
【问题描述】:

我无法让基于reveal.js 的应用程序在Heroku 上运行。我决定退后一步,尝试将 vanilla reveal.js 代码成功部署到 Heroku。我在这个基本步骤上遇到了麻烦。 Heroku 给出:

Application error
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.

我遵循了Getting Started on Heroku with Node.js 指南,但使用Full setup Readme 步骤从GitHub 获取了reveal.js 代码。以下是我遵循的步骤以及终端的结果:

$ git clone https://github.com/hakimel/reveal.js.git
Cloning into 'reveal.js'...
remote: Counting objects: 10252, done.
remote: Total 10252 (delta 0), reused 0 (delta 0), pack-reused 10252
Receiving objects: 100% (10252/10252), 7.58 MiB | 6.55 MiB/s, done.
Resolving deltas: 100% (5644/5644), done.
$ ls
moac-node-reveal    moac-solo-with-php  reveal.js
$ cd reveal.js/
$ ls
CONTRIBUTING.md LICENSE     bower.json  demo.html   js      package.json    test
Gruntfile.js    README.md   css     index.html  lib     plugin
$ npm install
npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated http2@3.3.7: Use the built-in module in node 9.0.0 or newer, instead

> node-sass@4.7.2 install /Users/simon/code/reveal.js/node_modules/node-sass
> node scripts/install.js

Cached binary found at /Users/simon/.npm/node-sass/4.7.2/darwin-x64-59_binding.node

> phantomjs-prebuilt@2.1.16 install /Users/simon/code/reveal.js/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Download already available at /var/folders/0n/rj76dqgx3yvd2tph37qlyvsm0000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip
Verified checksum of previously downloaded file
Extracting zip contents
Removing /Users/simon/code/reveal.js/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /var/folders/0n/rj76dqgx3yvd2tph37qlyvsm0000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip-extract-1514746311473/phantomjs-2.1.1-macosx -> /Users/simon/code/reveal.js/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /Users/simon/code/reveal.js/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

> node-sass@4.7.2 postinstall /Users/simon/code/reveal.js/node_modules/node-sass
> node scripts/build.js

Binary found at /Users/simon/code/reveal.js/node_modules/node-sass/vendor/darwin-x64-59/binding.node
Testing binary
Binary is fine
npm notice created a lockfile as package-lock.json. You should commit this file.
added 473 packages in 13.798s


   ╭─────────────────────────────────────╮
   │                                     │
   │   Update available 5.5.1 → 5.6.0    │
   │     Run npm i -g npm to update      │
   │                                     │
   ╰─────────────────────────────────────╯

$ npm start

> reveal.js@3.6.0 start /Users/simon/code/reveal.js
> grunt serve

(node:7173) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Started connect web server on http://localhost:8000

Running "watch" task
Waiting...
^C


   ╭─────────────────────────────────────╮
   │                                     │
   │   Update available 5.5.1 → 5.6.0    │
   │     Run npm i -g npm to update      │
   │                                     │
   ╰─────────────────────────────────────╯



$ heroku login
Enter your Heroku credentials:
Email: redacted@email.address
Password: **************
Two-factor code: ******
Logged in as redacted@email.address
$ node -v
v9.3.0
$ npm -v
5.5.1
$ git --version
git version 2.14.3 (Apple Git-98)
$ heroku create
Creating app... done, ⬢ calm-crag-42588
https://calm-crag-42588.herokuapp.com/ | https://git.heroku.com/calm-crag-42588.git
$ git push heroku master
Counting objects: 10020, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3988/3988), done.
Writing objects: 100% (10020/10020), 7.43 MiB | 677.00 KiB/s, done.
Total 10020 (delta 5525), reused 10020 (delta 5525)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Node.js app detected
remote: 
remote: -----> Creating runtime environment
remote:        
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote: 
remote: -----> Installing binaries
remote:        engines.node (package.json):  >=4.0.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:        
remote:        Resolving node version >=4.0.0...
remote:        Downloading and installing node 9.3.0...
remote:        Using default npm version: 5.5.1
remote: 
remote: -----> Restoring cache
remote:        Skipping cache restore (not-found)
remote: 
remote: -----> Building dependencies
remote:        Installing node modules (package.json)
remote:        up to date in 0.09s
remote: 
remote: -----> Caching build
remote:        Clearing previous node cache
remote:        Saving 2 cacheDirectories (default):
remote:        - node_modules (nothing to cache)
remote:        - bower_components (nothing to cache)
remote: 
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> web
remote: 
remote: -----> Compressing...
remote:        Done: 18.7M
remote: -----> Launching...
remote:        Released v3
remote:        https://calm-crag-42588.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/calm-crag-42588.git
 * [new branch]      master -> master
$ heroku ps:scale web=1
Scaling dynos... done, now running web at 1:Free
$ heroku open
$ heroku logs
2017-12-31T18:55:41.167608+00:00 app[api]: Release v2 created by user redacted@email.address
2017-12-31T18:55:40.984802+00:00 app[api]: Release v1 created by user redacted@email.address
2017-12-31T18:55:40.984802+00:00 app[api]: Initial release by user redacted@email.address
2017-12-31T18:55:41.167608+00:00 app[api]: Enable Logplex by user redacted@email.address
2017-12-31T18:56:13.000000+00:00 app[api]: Build started by user redacted@email.address
2017-12-31T18:56:20.523781+00:00 app[api]: Scaled to web@1:Free by user redacted@email.address
2017-12-31T18:56:20.502923+00:00 app[api]: Release v3 created by user redacted@email.address
2017-12-31T18:56:20.502923+00:00 app[api]: Deploy a0c01360 by user redacted@email.address
2017-12-31T18:56:13.000000+00:00 app[api]: Build succeeded
2017-12-31T18:56:22.217173+00:00 heroku[web.1]: Starting process with command `npm start`
2017-12-31T18:56:24.295551+00:00 app[web.1]: > reveal.js@3.6.0 start /app
2017-12-31T18:56:24.295401+00:00 app[web.1]: 
2017-12-31T18:56:24.295552+00:00 app[web.1]: > grunt serve
2017-12-31T18:56:24.295553+00:00 app[web.1]: 
2017-12-31T18:56:24.306026+00:00 app[web.1]: sh: 1: grunt: not found
2017-12-31T18:56:24.310223+00:00 app[web.1]: npm ERR! file sh
2017-12-31T18:56:24.310226+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-12-31T18:56:24.310227+00:00 app[web.1]: npm ERR! errno ENOENT
2017-12-31T18:56:24.310228+00:00 app[web.1]: npm ERR! syscall spawn
2017-12-31T18:56:24.311279+00:00 app[web.1]: npm ERR! reveal.js@3.6.0 start: `grunt serve`
2017-12-31T18:56:24.311803+00:00 app[web.1]: npm ERR! Failed at the reveal.js@3.6.0 start script.
2017-12-31T18:56:24.311414+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-12-31T18:56:24.311669+00:00 app[web.1]: npm ERR! 
2017-12-31T18:56:24.311943+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-12-31T18:56:24.317995+00:00 app[web.1]: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2017-12-31T18:56:24.318729+00:00 app[web.1]: 
2017-12-31T18:56:24.318964+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-12-31T18:56:24.319122+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-12-31T18_56_24_313Z-debug.log
2017-12-31T18:56:27.086467+00:00 heroku[web.1]: Starting process with command `npm start`
2017-12-31T18:56:24.393036+00:00 heroku[web.1]: Process exited with status 1
2017-12-31T18:56:24.405623+00:00 heroku[web.1]: State changed from starting to crashed
2017-12-31T18:56:24.407532+00:00 heroku[web.1]: State changed from crashed to starting
2017-12-31T18:56:30.585270+00:00 heroku[web.1]: State changed from starting to crashed
2017-12-31T18:56:30.556563+00:00 heroku[web.1]: Process exited with status 1
2017-12-31T18:56:30.393715+00:00 app[web.1]: 
2017-12-31T18:56:30.393731+00:00 app[web.1]: > reveal.js@3.6.0 start /app
2017-12-31T18:56:30.393732+00:00 app[web.1]: > grunt serve
2017-12-31T18:56:30.393732+00:00 app[web.1]: 
2017-12-31T18:56:30.400445+00:00 app[web.1]: sh: 1: grunt: not found
2017-12-31T18:56:30.404923+00:00 app[web.1]: npm ERR! file sh
2017-12-31T18:56:30.405234+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-12-31T18:56:30.405479+00:00 app[web.1]: npm ERR! errno ENOENT
2017-12-31T18:56:30.405725+00:00 app[web.1]: npm ERR! syscall spawn
2017-12-31T18:56:30.409574+00:00 app[web.1]: npm ERR! reveal.js@3.6.0 start: `grunt serve`
2017-12-31T18:56:30.409737+00:00 app[web.1]: npm ERR! spawn ENOENT
2017-12-31T18:56:30.410022+00:00 app[web.1]: npm ERR! 
2017-12-31T18:56:30.410205+00:00 app[web.1]: npm ERR! Failed at the reveal.js@3.6.0 start script.
2017-12-31T18:56:30.410375+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-12-31T18:56:30.428235+00:00 app[web.1]: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
2017-12-31T18:56:30.429020+00:00 app[web.1]: 
2017-12-31T18:56:30.429211+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-12-31T18:56:30.429337+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2017-12-31T18_56_30_412Z-debug.log
2017-12-31T18:56:36.818819+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=calm-crag-42588.herokuapp.com request_id=8b23ad0b-29bd-4a6a-bbf8-cd991fdc334a fwd="47.32.63.6" dyno= connect= service= status=503 bytes= protocol=https
2017-12-31T18:56:37.254436+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=calm-crag-42588.herokuapp.com request_id=8267e9aa-69ca-4998-b967-89e1db724b30 fwd="47.32.63.6" dyno= connect= service= status=503 bytes= protocol=https

【问题讨论】:

  • 错误提示您缺少 grunt。你可以在 package.json 中将它添加到 npm 的 postinstall 脚本中

标签: node.js heroku reveal.js


【解决方案1】:

有两件事解决了这个问题: 1. package.json:将 devDependencies 移至依赖项

"devDependencies": {
"express": "^4.16.2",
"grunt": "^1.0.1",
"grunt-autoprefixer": "^3.0.4",
"grunt-cli": "^1.2.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-qunit": "^1.2.0",
"grunt-contrib-uglify": "^2.3.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-retire": "^1.0.7",
"grunt-sass": "^2.0.0",
"grunt-zip": "^0.17.1",
"mustache": "^2.3.0",
"socket.io": "^1.7.4"},

...变成:

 "devDependencies": {},

还有:

"dependencies": {
"reveal-ga": "^0.1.0"}

...变成:

"dependencies": {
"reveal-ga": "^0.1.0",
"express": "^4.16.2",
"grunt": "^1.0.1",
"grunt-autoprefixer": "^3.0.4",
"grunt-cli": "^1.2.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-qunit": "^1.2.0",
"grunt-contrib-uglify": "^2.3.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-retire": "^1.0.7",
"grunt-sass": "^2.0.0",
"grunt-zip": "^0.17.1",
"mustache": "^2.3.0",
"socket.io": "^1.7.4"}
  1. Gruntfile.js:使用 $PORT 环境变量

    var port = grunt.option('port') || 8000;

...变成:

var port = grunt.option('port') || process.env.PORT || 8000;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 2011-12-18
    • 2014-08-02
    • 2020-07-28
    相关资源
    最近更新 更多