heroku找不到用于Ember快速启动部署的package.json

时间:2018-10-26 11:25:01

标签: node.js heroku ember.js package.json

在花时间解决此问题之前,请先阅读下面标题为“ It Works”的更新。

我已经构建了一个Ember(3.4)应用程序,该应用程序使用了Ember Fastboot。

它使用“灰烬服务”在本地构建并运行正常。

然后我将其部署到Heroku。它构建良好,但是当尝试访问它时,Heroku日志包含以下内容:

2018-10-26T10:59:25.887108+00:00 app[web.1]: Error: Couldn't find /app/dist/package.json. You may need to update your version of ember-cli-fastboot.
2018-10-26T10:59:25.887110+00:00 app[web.1]: at EmberApp.readPackageJSON (/app/node_modules/fastboot/src/ember-app.js:350:13)
2018-10-26T10:59:25.887112+00:00 app[web.1]: at new EmberApp (/app/node_modules/fastboot/src/ember-app.js:34:23)
2018-10-26T10:59:25.887114+00:00 app[web.1]: at FastBoot._buildEmberApp (/app/node_modules/fastboot/src/index.js:114:17)
2018-10-26T10:59:25.887115+00:00 app[web.1]: at new FastBoot (/app/node_modules/fastboot/src/index.js:52:10)
2018-10-26T10:59:25.887117+00:00 app[web.1]: at Worker.buildMiddleware (/app/node_modules/fastboot-app-server/src/worker.js:74:21)
2018-10-26T10:59:25.887118+00:00 app[web.1]: at Worker.start (/app/node_modules/fastboot-app-server/src/worker.js:48:30)
2018-10-26T10:59:25.887120+00:00 app[web.1]: at new FastBootAppServer (/app/node_modules/fastboot-app-server/src/fastboot-app-server.js:53:19)
2018-10-26T10:59:25.887122+00:00 app[web.1]: at Object.<anonymous> (/app/serve.js:3:14)
2018-10-26T10:59:25.887124+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:688:30)
2018-10-26T10:59:25.887125+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
2018-10-26T10:59:25.897530+00:00 app[web.1]: [2018-10-26T10:59:25.897Z][m4] forked worker 4029
2018-10-26T10:59:25.897719+00:00 app[web.1]: [2018-10-26T10:59:25.897Z][m4] worker online
2018-10-26T10:59:25.898240+00:00 app[web.1]: [2018-10-26T10:59:25.898Z][m4] worker exited with error code: 1
2018-10-26T10:59:25.922787+00:00 app[web.1]: Error waiting for process to terminate: No child processes

所以我在这里注意到的第一件事是它正在一个令人惊讶的地方寻找package.json。如果我在Heroku上浏览组成应用程序的文件,它们将像这样:

$ heroku run bash Running bash on ? aaaaa-bbbbbb-99999... up, run.8888 (Free) ~ $ ls -l total 628 -rw------- 1 u12345 dyno 19 Oct 26 10:01 Procfile -rw------- 1 u12345 dyno 1453 Oct 26 10:01 README.md drwx------ 9 u12345 dyno 4096 Oct 26 10:01 app drwx------ 2 u12345 dyno 4096 Oct 26 10:01 config -rw------- 1 u12345 dyno 1004 Oct 26 10:01 ember-cli-build.js drwx------ 116 u12345 dyno 4096 Oct 26 10:02 node_modules -rw------- 1 u12345 dyno 591407 Oct 26 10:02 package-lock.json -rw------- 1 u12345 dyno 1815 Oct 26 10:01 package.json drwx------ 2 u12345 dyno 4096 Oct 26 10:01 public -rw------- 1 u12345 dyno 464 Oct 26 10:01 serve.js -rw------- 1 u12345 dyno 581 Oct 26 10:01 testem.js drwx------ 5 u12345 dyno 4096 Oct 26 10:01 tests drwx------ 2 u12345 dyno 4096 Oct 26 10:01 vendor

日志显示heroku认为package.json将位于dist目录中,但实际上它位于根目录中。

我想我在准备将应用程序部署到Heroku时做错了什么-谁能告诉我为什么我看到此错误?


以下是一些可能相关的文件的内容

Procfile

web: node serve.js

ember-cli-build.js

'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    'asset-cache': {
      include: [
        'assets/**/*',
        'ember-welcome-page/images/*'
      ]
    },
    'esw-cache-fallback': {
      patterns: [ '/' ],
      version: '1' // Changing the version will bust the cache
    }
  });
  // Use `app.import` to add additional libraries to the generated
  // output files.
  //
  // If you need to use different assets in different
  // environments, specify an object as the first parameter. That
  // object's keys should be the environment name and the values
  // should be the asset to use in that environment.
  //
  // If the library that you are including contains AMD or ES6
  // modules that you would like to import into your application
  // please specify an object with the list of modules as keys
  // along with the exports of each module as its value.

  return app.toTree();
};

serve.js

const FastBootAppServer = require('fastboot-app-server');

let server = new FastBootAppServer({
  distPath: 'dist',
  gzip: true, // Optional - Enables gzip compression.
  beforeMiddleware(app) {
    app.use((request, response, next) => {
      if (request.headers['x-forwarded-proto'] === 'https') {
        return next();
      } else {
        return response.redirect(301, `https://${request.hostname}${request.url}`);
      }
    });
  }
});

package.json

{
  "name": "my-pwa",
  "version": "0.0.0",
  "private": true,
  "description": "Small description for my-pwa goes here",
  "repository": "",
  "license": "MIT",
  "author": "",
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "scripts": {
    "build": "ember build",
    "lint:hbs": "ember-template-lint .",
    "lint:js": "eslint .",
    "start": "ember serve",
    "test": "ember test"
  },
  "devDependencies": {
    "@ember/jquery": "^0.5.2",
    "@ember/optional-features": "^0.6.3",
    "broccoli-asset-rev": "^2.7.0",
    "ember-ajax": "^3.1.0",
    "ember-cli": "~3.4.3",
    "ember-cli-app-version": "^3.2.0",
    "ember-cli-babel": "^6.16.0",
    "ember-cli-dependency-checker": "^3.0.0",
    "ember-cli-eslint": "^4.2.3",
    "ember-cli-fastboot": "^2.0.0",
    "ember-cli-htmlbars": "^3.0.0",
    "ember-cli-htmlbars-inline-precompile": "^1.0.3",
    "ember-cli-inject-live-reload": "^1.8.2",
    "ember-cli-qunit": "^4.3.2",
    "ember-cli-sass": "^8.0.1",
    "ember-cli-sri": "^2.1.1",
    "ember-cli-template-lint": "^1.0.0-beta.1",
    "ember-cli-uglify": "^2.1.0",
    "ember-data": "~3.4.0",
    "ember-export-application-global": "^2.0.0",
    "ember-load-initializers": "^1.1.0",
    "ember-maybe-import-regenerator": "^0.1.6",
    "ember-paper": "^1.0.0-beta.18",
    "ember-resolver": "^5.0.1",
    "ember-service-worker": "^0.7.0",
    "ember-service-worker-asset-cache": "^0.6.3",
    "ember-service-worker-cache-fallback": "^0.6.1",
    "ember-source": "~3.4.0",
    "ember-web-app": "^2.3.0",
    "ember-welcome-page": "^3.2.0",
    "eslint-plugin-ember": "^5.2.0",
    "loader.js": "^4.7.0",
    "qunit-dom": "^0.7.1",
    "sass": "^1.14.3"
  },
  "engines": {
    "node": "6.* || 8.* || >= 10.*"
  },
  "dependencies": {
    "fastboot-app-server": "^1.1.2-beta.1"
  }
}

有效

我很高兴地说这现在正在工作。我不太高兴地说我不确定为什么。

出于特殊原因,我决定对应用程序进行一些外观上的更改,以查看是否可以让Heroku对其进行重建。我只更改了模板中的文字。

然后我做了:

  • 一个ember build
  • 一个ember serve -e production确认它在本地工作
  • git push heroku master

经过大量的处理(我的印象比我以前看到的要多,但是我不确定),该过程完成了,该应用程序现在可以在Heroku上托管了。

这不是一个非常令人满意的情况,因为我不确定是什么原因导致它起作用,但是也许这可以给陷入同样情况的其他人带来希望。

0 个答案:

没有答案