vendredi 26 octobre 2018

heroku can't find package.json for Ember fastboot deployment

I've built an Ember (3.4) app which makes use of Ember Fastboot.

It builds and runs OK locally using "ember serve".

Then I deployed it to Heroku. It builds OK but when an attempt is made to access it the Heroku logs contain the following :

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

So the first thing I notice here is that it's looking for package.json in (which I think is) a surprising place. If I browse the files which make up the app on Heroku they look like this :

$ 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

The log shows that heroku thinks package.json is going to be inside the dist directory but in fact it's in the root.

I guess i've done something wrong in preparing the app to be deployed to Heroku - can anyone tell me why I'm seeing this error ?


Here are the contents of a few files which may be relevant

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"
  }
}




Aucun commentaire:

Enregistrer un commentaire