Heroku Error. Cannot find module 'Mongoose' - javascript

For some odd reason (i have been deployed on Heroku for around 1.5 years) my instance decided to throw a weird error regarding not finding 'mongoose' after attempting to deploy again. Everything works on my local server and my .gitignore file ignores Node Modules. This is a React.js app with Expressjs and Mongoose.
Here is my Package.json:
{
"name": "drg-coming-soon",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack",
"server": "node server/index.js",
"start": "webpack && node server/index.js",
"react": "webpack -d --watch"
},
"heroku-run-build-script": true,
"author": "Randy Thomas",
"license": "ISC",
"devDependencies": {
"axios": "^0.18.0",
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"body-parser": "^1.18.3",
"express": "^4.15.0",
"jquery": "^3.1.1",
"mongoose": "^6.2.7",
"react-awesome-modal": "^2.0.5",
"request": "^2.81.0",
"webpack": "^4.28.3"
},
"dependencies": {
"axios": "^0.18.0",
"css-loader": "^2.0.1",
"dotenv": "^6.2.0",
"file-loader": "^2.0.0",
"react": "^15.4.2",
"react-autosuggest": "^9.4.3",
"react-dom": "^15.4.2",
"react-image": "^1.5.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-scripts": "^2.1.1",
"style-loader": "^0.23.1",
"twilio": "^3.33.2",
"url-loader": "^1.1.2",
"mongoose": "^6.2.7",
"webpack": "^4.28.3"
}
}
Here is my webpack.config.js
const path = require('path');
const SRC_DIR = path.join(__dirname, '/client/src');
const DIST_DIR = path.join(__dirname, '/client/dist');
module.exports = {
entry: `${SRC_DIR}/index.js`,
output: {
filename: 'bundle.js',
path: DIST_DIR,
},
module: {
//changed from loaders to rules
loaders: [
{
test: /\.jsx?/,
include: SRC_DIR,
loader: 'babel-loader',
query: {
presets: [
'#babel/preset-env',
'#babel/preset-react'
],
},
},
],
},
};
Here is my Database folder:
require('dotenv').config();
const mongoose = require('mongoose');
// dev
// process.env.mongourl
mongoose.connect(process.env.mongourl)
.catch(err => console.log('Mongo connection error', err));
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', () => {
console.log('MongoDB has connected');
});
// schemas
const comingSoonSchema = ({
address: String,
desc: String,
sqft: Number,
bed: String,
bath: String,
photoLink: String,
agent: String,
price: String,
year: Number,
eta: String,
premarket: String,
status: String,
timeStamp: { type: Date, default: Date.now },
})
// models
const ComingSoon = mongoose.model('ComingSoon', comingSoonSchema);
function save(e) {
console.log(e, "SAVE FUNC");
const obj = new ComingSoon({
address: e.address,
desc: e.desc,
sqft: e.sqft,
bed: e.bed,
bath: e.bath,
photoLink: e.photoLink,
agent: e.agent,
price: e.price,
year: e.year,
eta: e.eta,
status: e.status,
premarket: e.premarket
})
obj.save();
console.log("Data saved to MongoDB Database");
}
const funcs = {
save, ComingSoon,
};
module.exports = funcs;
And lastly here is the persisting error:
2022-03-23T01:33:06.685994+00:00 heroku[web.1]: Starting process with command `npm start`
2022-03-23T01:33:07.919434+00:00 app[web.1]:
2022-03-23T01:33:07.919447+00:00 app[web.1]: > drg-coming-soon#1.0.0 start
2022-03-23T01:33:07.919448+00:00 app[web.1]: > webpack && node server/index.js
2022-03-23T01:33:07.919448+00:00 app[web.1]:
2022-03-23T01:33:07.965317+00:00 app[web.1]: One CLI for webpack must be installed. These are recommended choices, delivered as separate packages:
2022-03-23T01:33:07.965319+00:00 app[web.1]: - webpack-cli (https://github.com/webpack/webpack-cli)
2022-03-23T01:33:07.965319+00:00 app[web.1]: The original webpack full-featured CLI.
2022-03-23T01:33:07.965784+00:00 app[web.1]: We will use "npm" to install the CLI via "npm install -D".
2022-03-23T01:33:08.131129+00:00 app[web.1]: Do you want to install 'webpack-cli' (yes/no): node:internal/modules/cjs/loader:936
2022-03-23T01:33:08.131131+00:00 app[web.1]: throw err;
2022-03-23T01:33:08.131131+00:00 app[web.1]: ^
2022-03-23T01:33:08.131132+00:00 app[web.1]:
2022-03-23T01:33:08.131132+00:00 app[web.1]: Error: Cannot find module 'mongoose'
2022-03-23T01:33:08.131132+00:00 app[web.1]: Require stack:
2022-03-23T01:33:08.131133+00:00 app[web.1]: - /app/database/index.js
2022-03-23T01:33:08.131136+00:00 app[web.1]: - /app/server/index.js
2022-03-23T01:33:08.131136+00:00 app[web.1]: at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
2022-03-23T01:33:08.131137+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:778:27)
2022-03-23T01:33:08.131137+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19)
2022-03-23T01:33:08.131138+00:00 app[web.1]: at require (node:internal/modules/cjs/helpers:102:18)
2022-03-23T01:33:08.131138+00:00 app[web.1]: at Object.<anonymous> (/app/database/index.js:2:18)
2022-03-23T01:33:08.131139+00:00 app[web.1]: at Module._compile (node:internal/modules/cjs/loader:1103:14)
2022-03-23T01:33:08.131139+00:00 app[web.1]: at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Module.load (node:internal/modules/cjs/loader:981:32)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Function.Module._load (node:internal/modules/cjs/loader:822:12)
2022-03-23T01:33:08.131140+00:00 app[web.1]: at Module.require (node:internal/modules/cjs/loader:1005:19) {
2022-03-23T01:33:08.131141+00:00 app[web.1]: code: 'MODULE_NOT_FOUND',
2022-03-23T01:33:08.131141+00:00 app[web.1]: requireStack: [ '/app/database/index.js', '/app/server/index.js' ]
2022-03-23T01:33:08.131142+00:00 app[web.1]: }
2022-03-23T01:33:08.265674+00:00 heroku[web.1]: Process exited with status 1
2022-03-23T01:33:08.447674+00:00 heroku[web.1]: State changed from starting to crashed
2022-03-23T01:32:58.202124+00:00 app[api]: Release v158 created by user bookingrlthomas#gmail.com
2022-03-23T01:32:58.202124+00:00 app[api]: Deploy ad551b5e by user bookingrlthomas#gmail.com
2022-03-23T01:33:00.927332+00:00 app[api]: Deploy ad551b5e by user bookingrlthomas#gmail.com
2022-03-23T01:33:00.927332+00:00 app[api]: Release v159 created by user bookingrlthomas#gmail.com
2022-03-23T01:33:51.331557+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=drgcomingsoonlistings.herokuapp.com request_id=fd27788b-e166-49fd-8830-b0da493e7e62 fwd="47.45.81.207" dyno= connect= service= status=503 bytes= protocol=https
2022-03-23T01:33:52.166634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=drgcomingsoonlistings.herokuapp.com request_id=4967681e-a5a9-41b9-9129-65258f9b9983 fwd="47.45.81.207" dyno= connect= service= status=503 bytes= protocol=https

The error is most likely coming from the fact that you have mongoose in your "devDependencies". Try moving it to your "dependencies", then running npm install. You may run into the same issue with express and a few others under "devDependencies". Hope this helps.

It does not make any sense, but if mongoose is both in dev dependencies and in dependencies, heroku goes nuts. It can be ONLY in dependencies. After deleting it from dev dependencies, do npm install. It will work without any issues.

Related

Error when import firebase-functions-test when testing with mocha

I am trying to setup a Firebase Cloud Functions repo to run mocha test. However, it throws the following error when I use import * as firebase from "firebase-functions-test"; or const firebase = require("firebase-functions-test")();. You can see in my code that I haven't even called the actual firebase functions yet so I think this a setup issue.
Question: What change do I need to make mocha test running for Firebase Functions testing using import syntax?
Working test code
import { assert } from "chai";
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
});
});
Failed Test Code using require
const test = require("firebase-functions-test")();
import { assert } from "chai";
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
test.cleanup();
});
});
Failed code using import
import * as firebase from "firebase-functions-test";
import { assert } from "chai";
const test = firebase();
describe("Sanity Check", () => {
it("should pass", () => {
assert.equal(0, 0);
test.cleanup();
});
});
Error for the failure
> functions# test /Users/cupidchan/temp/functions
> mocha -r ts-node/register test/**/*.spec.ts
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/encoder' is not defined by "exports" in /Users/cupidchan/temp/functions/node_modules/firebase-functions/package.json
at new NodeError (internal/errors.js:322:7)
at throwExportsNotFound (internal/modules/esm/resolve.js:322:9)
at packageExportsResolve (internal/modules/esm/resolve.js:545:3)
at resolveExports (internal/modules/cjs/loader.js:450:36)
at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/cupidchan/temp/functions/node_modules/#cspotcode/source-map-support/source-map-support.js:679:30)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/Users/cupidchan/temp/functions/node_modules/firebase-functions-test/lib/providers/firestore.js:26:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.<anonymous> (/Users/cupidchan/temp/functions/node_modules/firebase-functions-test/lib/features.js:9:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at module.exports (/Users/cupidchan/temp/functions/node_modules/firebase-functions-test/lib/index.js:30:20)
at Object.<anonymous> (/Users/cupidchan/temp/functions/test/index.spec.ts:9:14)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Module.m._compile (/Users/cupidchan/temp/functions/node_modules/ts-node/src/index.ts:1371:23)
at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Object.require.extensions.<computed> [as .ts] (/Users/cupidchan/temp/functions/node_modules/ts-node/src/index.ts:1374:12)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object.exports.requireOrImport (/Users/cupidchan/temp/functions/node_modules/mocha/lib/nodejs/esm-utils.js:56:20)
at async Object.exports.loadFilesAsync (/Users/cupidchan/temp/functions/node_modules/mocha/lib/nodejs/esm-utils.js:88:20)
at async singleRun (/Users/cupidchan/temp/functions/node_modules/mocha/lib/cli/run-helpers.js:125:3)
at async Object.exports.handler (/Users/cupidchan/temp/functions/node_modules/mocha/lib/cli/run.js:374:5)
npm ERR! Test failed. See above for more details.
package.json
{
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log",
"test": "mocha -r ts-node/register test/**/*.spec.ts --reporter spec"
},
"engines": {
"node": "14"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"#types/chai": "^4.2.22",
"#types/mocha": "^9.0.0",
"#types/node": "^16.11.11",
"#typescript-eslint/eslint-plugin": "^3.9.1",
"#typescript-eslint/parser": "^3.8.0",
"chai": "^4.3.4",
"eslint": "^7.6.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-prettier": "^4.0.0",
"esm": "^3.2.25",
"firebase-functions-test": "^0.2.3",
"mocha": "^9.1.3",
"prettier": "^2.5.0",
"ts-node": "^10.4.0",
"typescript": "^3.8.0"
},
"private": true
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": ["src", "test"]
}
This error should be resolved after specifying the latest version of the
firebase-functions, v3.16.0, and
firebase-functions-test, v0.3.3.

Angular Fire with Universal SSR | Everything works, but the problem is while building my app [duplicate]

I'm dealing with this issue for almost two weeks now. I tried a lot of workarounds but none seems to be working. I've installed angular-fire and firebase to its latest version, tried ng add #angular/fire, configured custom webpack.config.ts, tried rolling back to every suggested previous version. None fixed this issue.
The Actual Error:
de-10#de10-LIFEBOOK-A555:~/Desktop$ node dist/server.js
internal/modules/cjs/loader.js:797
throw err;
^
Error: Cannot find module 'firebase/app'
Require stack:
- /home/de-10/Desktop/dist/server.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
at Function.Module._load (internal/modules/cjs/loader.js:687:27)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/de-10/Desktop/dist/server.js:125276:18)
at __webpack_require__ (/home/de-10/Desktop/dist/server.js:20:30)
at Module.<anonymous> (/home/de-10/Desktop/dist/server.js:125199:70)
at __webpack_require__ (/home/de-10/Desktop/dist/server.js:20:30)
at Module.<anonymous> (/home/de-10/Desktop/dist/server.js:124984:78)
at __webpack_require__ (/home/de-10/Desktop/dist/server.js:20:30) {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/home/de-10/Desktop/dist/server.js' ]
}
And I can't let go of Firebase cause then I face:
ERROR in ../node_modules/#angular/fire/auth/auth.d.ts:4:28 - error TS2307: Cannot find module 'firebase/app'.
4 import { User, auth } from 'firebase/app';
~~~~~~~~~~~~~~
../node_modules/#angular/fire/firebase.app.module.d.ts:2:74 - error TS2307: Cannot find module 'firebase/app'.
2 import { auth, database, messaging, storage, firestore, functions } from 'firebase/app';
~~~~~~~~~~~~~~
../node_modules/#angular/fire/firestore/collection-group/collection-group.d.ts:2:27 - error TS2307: Cannot find module 'firebase/app'.
~~~~~~~~~~~~~
.
.
.
app/services/notification.service.ts:29:38 - error TS2339: Property 'id' does not exist on type 'QueryDocumentSnapshot<unknown>'.
29 id: snap.payload.doc.id,
~~
app/services/notification.service.ts:68:35 - error TS2339: Property 'type' does not exist on type 'DocumentChange<unknown>'.
68 return snap.payload.type
~~~~
.
.
.
package.json
{
"name": "universal-ssr",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "npm run build:ssr",
"staging": "npm run build:ssr-staging && npm run serve:ssr",
"production": "npm run build:ssr && npm run serve:ssr",
"prod": "npm run build:ssr-production && npm run serve:ssr",
"build": "ng build --prod",
"test": "ng test",
"dev-start": "ng serve",
"ng serve": "ng serve --aot",
"lint": "ng lint",
"e2e": "ng e2e",
"build:ssr": "npm run build:client-and-server-bundles && npm run webpack:server",
"build:ssr-staging": "npm run build:client-and-server-bundles-staging && npm run webpack:server",
"build:ssr-production": "npm run build:client-and-server-bundles-production && npm run webpack:server",
"serve:ssr": "node dist/server.js",
"build:client-and-server-bundles": "ng build --prod --build-optimizer && ng run universal-ssr:server --bundleDependencies all",
"build:client-and-server-bundles-staging": "ng build --c=staging --build-optimizer=true --stats-json && ng run universal-ssr:server",
"build:client-and-server-bundles-production": "ng build --c=production --build-optimizer=true && ng run universal-ssr:server --bundleDependencies all",
"webpack:server": "webpack --config webpack.config.js --progress --colors",
"webpack:analyzer": "webpack-bundle-analyzer dist/browser/stats.json",
"compodoc": "npx compodoc -p src/tsconfig.app.json -o"
},
"private": true,
"dependencies": {
"#angular/animations": "^8.2.14",
"#angular/cdk": "^5.2.5",
"#angular/common": "^8.2.14",
"#angular/compiler": "^8.2.14",
"#angular/core": "^8.2.14",
"#angular/fire": "^5.4.2",
"#angular/forms": "^8.2.14",
"#angular/material": "^5.2.5",
"#angular/platform-browser": "^8.2.14",
"#angular/platform-browser-dynamic": "^8.2.14",
"#angular/platform-server": "^8.2.14",
"#angular/pwa": "^0.803.24",
"#angular/router": "^8.2.14",
"#angular/service-worker": "^8.2.14",
"#ng-bootstrap/ng-bootstrap": "^4.0.0",
"#nguniversal/express-engine": "^6.1.0",
"#nguniversal/module-map-ngfactory-loader": "^6.1.0",
"angular2-datetimepicker": "^1.1.1",
"bootstrap": "^4.4.1",
"city-timezones": "^1.2.0",
"core-js": "^2.6.11",
"cors": "^2.8.4",
"express": "^4.17.1",
"firebase": "^7.13.1",
"jquery": "^3.4.1",
"moment-timezone": "^0.5.27",
"ng-bootstrap": "^1.6.3",
"ng2-search-filter": "^0.5.1",
"ngx-clipboard": "12.2.1",
"ngx-google-places-autocomplete": "^2.0.4",
"ngx-pagination": "^3.3.1",
"ngx-spinner": "^2.0.0",
"ngx-toggle-switch": "^2.0.5",
"ngx-ui-switch": "^8.3.0",
"rxjs": "^6.5.4",
"rxjs-compat": "^6.0.0",
"save": "^2.4.0",
"ts-loader": "^4.0.0",
"tslib": "^1.10.0",
"uuid": "^3.4.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.803.23",
"#angular/cli": "^8.3.23",
"#angular/compiler-cli": "^8.2.14",
"#angular/http": "^7.2.16",
"#angular/language-service": "^8.2.14",
"#types/jasmine": "2.8.3",
"#types/jasminewd2": "^2.0.8",
"#types/node": "^6.14.9",
"codelyzer": "^5.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.1.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "5.4.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~3.5.3",
"webpack-cli": "^3.1.0"
}
}
webpack.config.js:
// Work around for https://github.com/angular/angular-cli/issues/7200
const path = require('path');
const webpack = require('webpack');
// change the regex to include the packages you want to exclude
const regex = /firebase\/(app|firestore)/;
module.exports = {
mode: 'production',
entry: {
// This is our Express server for Dynamic universal
server: './server.ts'
},
externals: {
'./dist/server/main': 'require("./server/main")'
},
target: 'node',
node: {
__dirname: false,
__filename: false,
},
resolve: { extensions: ['.ts', '.js'] },
target: 'node',
mode: 'none',
// this makes sure we include node_modules and other 3rd party libraries
externals: [/node_modules/, function (context, request, callback) {
// exclude firebase products from being bundled, so they will be loaded using require() at runtime.
if (regex.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
}],
optimization: {
minimize: false
},
output: {
// Puts the output at the root of the dist folder
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
module: {
noParse: /polyfills-.*\.js/,
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{
// Mark files inside `#angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /(\\|\/)#angular(\\|\/)core(\\|\/).+\.js$/,
parser: { system: true },
},
]
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{} // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{}
)
]
};
server.ts:
import 'zone.js/dist/zone-node';
import * as express from 'express';
/* const express = require('express');
const join = require('path'); */
const compression = require('compression')
import { join } from 'path';
// Express server
const app = express();
// gzip
app.use(compression())
const PORT = process.env.PORT || 4000;
const DIST_FOLDER = join(__dirname, 'browser');/* 'dist/browser' */
// * NOTE :: leave this as require() since this file is built Dynamically from webpack
const { AppServerModuleNgFactory, LAZY_MODULE_MAP, ngExpressEngine, provideModuleMap } = require('./dist/server/main');
// Our Universal express-engine (found # https://github.com/angular/universal/tree/master/modules/express-engine)
app.engine('html', ngExpressEngine({
bootstrap: AppServerModuleNgFactory,
providers: [
provideModuleMap(LAZY_MODULE_MAP)
]
}));
app.set('view engine', 'html');
app.set('views', DIST_FOLDER);
// Serve static files from /browser
app.get('*.*', express.static(DIST_FOLDER, {
maxAge: '1y'
}));
// All regular routes use the Universal engine
app.get('*', (req, res) => {
res.render('index', { req });
});
// Start up the Node server
app.listen(PORT, () => {
console.log(`Node Express server listening on http://localhost:${PORT}`);
});
You're getting this error because you're excluding firebase dependencies with this =>
const regex = /firebase\/(app|firestore)/;
module.exports = {
// this makes sure we include node_modules and other 3rd party libraries
externals: [/node_modules/, function (context, request, callback) {
// exclude firebase products from being bundled, so they will be loaded using require() at runtime.
if (regex.test(request)) {
return callback(null, 'commonjs ' + request);
}
callback();
}],
};
Remove this
if (regex.test(request)) {
return callback(null, 'commonjs ' + request);
}
and your app will be fine.
One workaround is to install npm packages (firebase and #angular/fire) beside the dist folder and then run the deployment script.

403 error when deploying a Node.js app on Heroku

Earlier, I was getting the following error (from the Chrome console) when trying to open a Node.js app using Heroku:
Refused to load the image 'https://browser-rpg-app.herokuapp.com/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
This was accompanied by a 403. I managed to fix it by adding this line:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js 'unsafe-inline'">
Now the first error is gone, but I'm still getting a 403. I can run the app flawlessly on heroku local web, but not when I actually deploy. Here's what the log says:
2019-12-02T22:41:29.000000+00:00 app[api]: Build succeeded
2019-12-02T22:41:32.617542+00:00 heroku[web.1]: Starting process with command `node app.js`
2019-12-02T22:41:36.786903+00:00 heroku[web.1]: State changed from starting to up
2019-12-02T22:42:00.484013+00:00 app[web.1]: ForbiddenError: Forbidden
2019-12-02T22:42:00.484062+00:00 app[web.1]: at SendStream.error (/app/node_modules/send/index.js:270:31)
2019-12-02T22:42:00.484066+00:00 app[web.1]: at SendStream.pipe (/app/node_modules/send/index.js:553:12)
2019-12-02T22:42:00.484068+00:00 app[web.1]: at sendfile (/app/node_modules/express/lib/response.js:1103:8)
2019-12-02T22:42:00.484071+00:00 app[web.1]: at ServerResponse.sendFile (/app/node_modules/express/lib/response.js:433:3)
2019-12-02T22:42:00.484074+00:00 app[web.1]: at index (/app/routes/index.js:9:9)
2019-12-02T22:42:00.484077+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-12-02T22:42:00.484079+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:137:13)
2019-12-02T22:42:00.484081+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2019-12-02T22:42:00.484083+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2019-12-02T22:42:00.484085+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:281:22
2019-12-02T22:42:00.482239+00:00 heroku[router]: at=info method=GET path="/" host=browser-rpg-app.herokuapp.com request_id=845c8d30-4ca7-44f4-ab69-ae312e722b1b fwd="68.174.27.246" dyno=web.1 connect=1ms service=21ms status=403 bytes=380 protocol=https
As you can see, there's no helpful message or explanation, it just says forbidden. I really have no clue what the problem could be, but here's a bunch of important/relevant files:
app.js:
const express = require("express");
const configRoutes = require("./routes");
const static = express.static(__dirname + '/public');
const app = express();
app.use("/public", static);
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const cookieParser = require("cookie-parser");
app.use(cookieParser());
configRoutes(app);
app.listen(process.env.PORT || 3000, () => {
console.log("The application is running on http://localhost:3000");
if (process && process.send) process.send({done: true});
});
package.json:
{
"name": "browserrpg",
"version": "1.0.0",
"description": "",
"main": "app.js",
"engines": {
"node": "10.16.3"
},
"dependencies": {
"angular": "^1.7.2",
"angular-route": "^1.7.2",
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"express": "^4.16.3",
"mongodb": "^3.1.1",
"npm": "^6.2.0",
"uuid": "^3.3.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"repository": {
"type": "git",
"url": (git url here, removed for privacy)
},
"author": "",
"license": "ISC",
}
Procfile:
web: node app.js
In case it's relevant, here's the "/" route that Heroku calls:
const index = (req, res) => {
res.sendFile(path.join(__dirname, "..\\public\\html", "index.html"));
return;
}
And here's the constructor that sets up all the routes:
const constructorMethod = app => {
app.get("/", index);
app.get("/game", gameGet);
app.post("/game", gamePost);
app.use("*", (req, res) => {
res.status(404).json({ error: "Not found" });
});
};
Here's my file structure as well:
BrowserRPG
│ README.md
│ Procfile
| app.js
| mongoCollections.js
| mongoConnection.js
| package.json
| settings.json
│
└───data
│ enemydata.js
│ gamecalc.js
| gamedata.js
| index.js
│
│
└───public
│
└───css
| main.css
|
└───html
| game.html
| index.html
|
└───js
| angular.js
| angularActiveGame.js
|
└───routes
| index.js
I'm also using a mongodb database, but I don't think that's causing the problem, considering that I haven't even attempted to connect it to Heroku yet, and you don't need to have a db running to get to the first page of the app. Is there something here that might be causing the error? Thanks.
So I finally figured it out, the solution was actually annoyingly simple. In my "/" GET route, the path contains a .., which was being viewed as malicious, and therefore rejected. I changed it to this:
res.sendFile(path.join(appRoot, "public/html", "index.html"));
appRoot is a global variable that points to the root directory of the application. Hopefully this helps someone who may be having a similar issue.

Including local npm libraries

I am using the serverless framework to develop lambda functions in the aws cloud. Currently, I am running into an issue when including a library that I made. It seems the recommended way to do this is to either:
1) npm install <path/to/your/lib>
2) npm link and related commands
In the first situation, when using npm install ../libs, and include the module using const Libs = require('libs') , the package appears to install correctly (it is listed in the package.json). However, on uploading the service to aws or using sls invoke local -f my-func the following error is thrown:
{ Error: Cannot find module 'libs'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:419:18)
at __webpack_require__ (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:20:30)
at Object.<anonymous> (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:376:16)
at __webpack_require__ (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:20:30)
at Object.defineProperty.value (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:63:18)
at Object.<anonymous> (/Users/Documents/GitHub/serverless-cloud-functions/dynamodb-stream-handlers/.webpack/service/service-provider-users-archive-stream-handler.js:66:10)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at AwsInvokeLocal.invokeLocalNodeJs (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:258:33)
at AwsInvokeLocal.invokeLocal (/usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:125:19)
at AwsInvokeLocal.tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:773:18)
at tryOnImmediate (timers.js:734:5)
at processImmediate [as _immediateCallback] (timers.js:711:5) code: 'MODULE_NOT_FOUND' }
Using npm link gives similar results as well. I have a hunch that the issue has to do with the fact that I'm using babel and webpack, but I'm not sure.
Here is the contents of my webpack.config.js file:
const slsw = require("serverless-webpack");
const nodeExternals = require("webpack-node-externals");
module.exports = {
entry: slsw.lib.entries,
target: "node",
externals: [nodeExternals()],
module: {
rules: [
{
test: /\.js$/,
loader: "babel-loader",
include: __dirname,
exclude: /node_modules/
}
]
},
};
Including the individual clients, instead of the overall lib seems to have solved the above error, but now I am faced with a new error.
Here is the serverless.yml file:
service: instant-response-api
plugins:
- serverless-webpack
- serverless-domain-manager
- serverless-plugin-aws-alerts
custom:
alerts:
topics:
alarm: ${file(./env.yml):${opt:stage}.ADMIN_SNS_TOPIC_ARN}
alarms:
- functionErrors
webpackIncludeModules: true
customDomain:
domainName: ${file(./env.yml):${opt:stage}.DOMAIN_NAME}
basepath: ''
stage: ${opt:stage}
createdRoute53Record: true
provider:
name: aws
runtime: nodejs6.10
region: us-west-2
stage: ${opt:stage}
environment:
${file(./env.yml):${opt:stage}}
iamRoleStatements:
- Effect: "Allow"
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:DescribeTable
Resource: "arn:aws:dynamodb:us-west-2:*:*"
- Effect: "Allow"
Action:
- sns:Publish
- sns:CreateTopic
Resource: "arn:aws:sns:*:*:*"
functions:
create-service-provider-number:
handler: create-service-provider-number.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: create-service-provider-number/{serviceProviderId}
method: post
cors: true
alarms:
- functionErrors
service-provider-sms-handler:
handler: service-provider-sms-handler.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: service-provider-sms-handler/{serviceProviderId}
method: post
cors: true
alarms:
- functionErrors
end-user-voice-handler:
handler: end-user-voice-handler.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: end-user-voice-handler/{userId}/{propertyId}
method: post
cors: true
alarms:
- functionErrors
end-user-sms-handler:
handler: end-user-sms-handler.main
memorySize: 3008
timeout: 30
logRetentionInDays: 30
events:
- http:
path: end-user-sms-handler/{userId}/{propertyId}
method: post
cors: true
alarms:
- functionErrors
And here is package.json:
{
"name": "instant-response-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"aws-sdk": "^2.177.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-3": "^6.24.1",,
"jest": "^22.4.2",
"jest-cli": "^22.1.4",,
"serverless-domain-manager": "^2.1.0",
"serverless-plugin-aws-alerts": "^1.2.4",
"serverless-webpack": "^4.2.0",
"webpack": "^3.10.0",
"webpack-node-externals": "^1.6.0"
},
"dependencies": {
"#google/maps": "^0.4.5",
"babel-runtime": "^6.26.0",
"query-string": "^5.0.1",
"twilioClient": "file:../libs/twilioClient",
"dynamodbClient": "file:../libs/dynamodbClient",
"snsClient": "file:../libs/snsClient"
}
}
My new error:
START RequestId: a9962b1d-21dd-11e8-bc1e-35d1e2dcfd8e Version: $LATEST
Syntax error in module 'service-provider-sms-handler': SyntaxError
async sendSms({to, from, msg}) {
^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
END RequestId: a9962b1d-21dd-11e8-bc1e-35d1e2dcfd8e
REPORT RequestId: a9962b1d-21dd-11e8-bc1e-35d1e2dcfd8e Duration: 5.62 ms Billed Duration: 100 ms Memory Size: 3008 MB Max Memory Used: 22 MB

Why cannot i successfully deploy my nodejs app to heroku?

This is first time i deploy to heroku. The deployment itself was successful but when i open app i get an error.
Looks like a problem resides inside package.json or Procfile.
The fixing maybe obvious for you guys but i am new to heroku so don't come angry.
[EDIT] I have disabled production mode by running heroku config:set NPM_CONFIG_PRODUCTION=false but error still remains just logs has been changed
Thanks in advance for you help guys!
Details below:
app - https://evening-retreat-75182.herokuapp.com
github repo - https://github.com/dagman/Recipebook
Procfile
web: npm run start:production
package.json
{
"name": "Recipebook",
"version": "1.0.0",
"description": "The most kickass app for your cooking recipes",
"main": "index.js",
"engines": {
"node": ">=5.0 <7",
"npm": ">=3.0 <4"
},
"repository": {
"type": "git",
"url": "https://github.com/dagman/Recipebook.git"
},
"keywords": [
"recipe",
"recipes",
"recipebook"
],
"author": "Islam Ibakaev <islamibakaev#gmail.com> (https://github.com/dagman)",
"license": "MIT",
"bugs": {
"url": "https://github.com/dagman/Recipebook/issues"
},
"homepage": "https://github.com/dagman/Recipebook",
"scripts": {
"start": "better-npm-run start",
"start:production": "npm run build && npm run start:prod",
"start:prod": "better-npm-run start:prod",
"build": "npm run clean:build && better-npm-run build",
"lint": "npm run lint:js && npm run lint:style",
"lint:js": "better-npm-run lint:js",
"lint:style": "better-npm-run lint:style",
"test": "better-npm-run test",
"test:watch": "npm test -- --no-single-run",
"clean:all": "npm run clean:build && npm run clean:coverage",
"clean:build": "better-npm-run clean:build",
"clean:coverage": "better-npm-run clean:coverage",
"coveralls": "better-npm-run coveralls && npm run test:clean"
},
"betterScripts": {
"start": {
"command": "nodemon ./index.js",
"env": {
"NODE_PATH": "./src",
"NODE_ENV": "development",
"PORT": "3000"
}
},
"start:prod": {
"command": "node ./index.js",
"env": {
"NODE_PATH": "./src",
"NODE_ENV": "production",
"PORT": "8080"
}
},
"build": {
"command": "webpack --progress --display-error-details --config ./tools/webpack/config.babel",
"env": {
"NODE_ENV": "production",
"BABEL_ENV": "es"
}
},
"lint:js": {
"command": "eslint -c .eslintrc ./src ./tools ./index.js"
},
"lint:style": {
"command": "stylelint \"./src/**/*.css\""
},
"test": {
"command": "karma start ./tools/testing/karma.conf.js --single-run",
"env": {
"NODE_ENV": "test"
}
},
"clean:build": {
"command": "rimraf ./public/dist"
},
"clean:coverage": {
"command": "rimraf ./coverage"
},
"coveralls": {
"command": "cat ./coverage/lcov/lcov.info | coveralls"
}
},
"dependencies": {
"autoprefixer": "^6.5.0",
"axios": "^0.14.0",
"babel-core": "^6.16.0",
"babel-polyfill": "^6.16.0",
"babel-runtime": "^6.11.6",
"chalk": "^1.1.3",
"classnames": "^2.2.5",
"compression": "^1.6.2",
"express": "^4.14.0",
"extract-text-webpack-plugin": "^2.0.0-beta.3",
"flexboxgrid": "^6.3.1",
"helmet": "^2.3.0",
"hpp": "^0.2.1",
"immutable": "^3.8.1",
"material-ui": "^0.16.0",
"morgan": "^1.7.0",
"opn": "^4.0.2",
"radium": "^0.18.1",
"react": "^15.3.2",
"react-addons-shallow-compare": "^15.3.2",
"react-css-modules": "^3.7.10",
"react-dom": "^15.3.2",
"react-flexbox-grid": "^0.10.2",
"react-helmet": "^3.1.0",
"react-immutable-proptypes": "^2.1.0",
"react-redux": "^4.4.5",
"react-responsive": "^1.1.5",
"react-router": "^2.8.1",
"react-router-redux": "^4.0.6",
"react-tap-event-plugin": "^1.0.0",
"redbox-react": "^1.3.1",
"redux": "^3.6.0",
"redux-immutable": "^3.0.8",
"redux-logger": "^2.7.0",
"redux-thunk": "^2.1.0",
"serialize-javascript": "^1.3.0",
"serve-favicon": "^2.3.0",
"stylelint-webpack-plugin": "^0.4.0",
"webpack": "^2.1.0-beta.25",
"webpack-dev-middleware": "^1.8.3",
"webpack-hot-middleware": "^2.12.2",
"webpack-isomorphic-tools": "^2.5.8"
},
"devDependencies": {
"assets-webpack-plugin": "^3.4.0",
"babel-eslint": "^7.0.0",
"babel-loader": "^6.2.5",
"babel-plugin-istanbul": "^2.0.1",
"babel-plugin-system-import-transformer": "^2.4.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"better-npm-run": "0.0.11",
"chai": "^3.5.0",
"chai-enzyme": "^0.5.2",
"coveralls": "^2.11.14",
"css-loader": "^0.25.0",
"enzyme": "^2.4.1",
"eslint": "^3.7.0",
"eslint-config-airbnb": "^12.0.0",
"eslint-loader": "^1.5.0",
"eslint-plugin-import": "^2.0.0",
"eslint-plugin-jsx-a11y": "^2.2.2",
"eslint-plugin-react": "^6.3.0",
"file-loader": "^0.9.0",
"image-webpack-loader": "^2.0.0",
"imports-loader": "^0.6.5",
"json-loader": "^0.5.4",
"karma": "^1.3.0",
"karma-cli": "^1.0.1",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.2.0",
"karma-mocha-reporter": "^2.2.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"mocha": "^3.1.0",
"node-sass": "^3.10.1",
"nodemon": "^1.10.2",
"null-loader": "^0.1.1",
"phantomjs": "^2.1.7",
"postcss": "^5.2.4",
"postcss-loader": "^0.13.0",
"react-addons-test-utils": "^15.3.2",
"react-hot-loader": "^3.0.0-beta.5",
"redux-mock-store": "^1.2.1",
"rimraf": "^2.5.4",
"sass-loader": "^4.0.2",
"sinon": "^2.0.0-pre.2",
"style-loader": "^0.13.1",
"stylelint": "^7.3.1",
"stylelint-config-standard": "^13.0.2",
"url-loader": "^0.5.7"
}
}
[EDIT] heroku logs
Hash: f14d96e1104722075ee5
2016-10-29T19:33:52.794597+00:00 app[web.1]: Version: webpack 2.1.0-beta.25
2016-10-29T19:33:52.794598+00:00 app[web.1]: Time: 36390ms
2016-10-29T19:33:52.794599+00:00 app[web.1]: Asset Size Chunks Chunk Names
2016-10-29T19:33:52.794600+00:00 app[web.1]: app.437ada71305f4f7f06fa.js 273 kB 0 [emitted] app
2016-10-29T19:33:52.794602+00:00 app[web.1]: app.437ada71305f4f7f06fa.css.map 34 kB 0 [emitted] app
2016-10-29T19:33 54% building modules 459/619 modules 160 active ...abel-runtime/core-js/object/assign.js
2016-10-29T19:33:52.794582+00:00 app[ 67% building modules 608/640 modules 32 active ...e-js/modules/_array-species-create.js
66% building modules 800/846 modules 46 active ...ixer/lib/static/plugins/transitint.js
2016-10-29 64% building modules 566/625 modules 59 active ...index.js!/app/src/theme/normalize.css
65% building modules 706/769 modules 63 active ...dules/core-js/library/modules/_has.js
66% building modules 691/728 modules 37 active /app/node_modules/fbjs/lib/isTextNode.js
66% building modules 828/875 modules 47 active ...react-addons-create-fragment/index.js
2016-10-29T19:33:52.794604+00:00 app[web.1]: + 977 hidden modules
2016-10-29T19:33:52.794605+00:00 app[web.1]: + 2 hidden modules
2016-10-29T19:33:52.794606+00:00 app[web.1]: Child extract-text-webpack-plugin:
2016-10-29T19:33:52.794607+00:00 app[web.1]: + 2 hidden modules
2016-10-29T19:33:52.794608+00:00 app[web.1]: Child extract-text-webpack-plugin:
2016-10-29T19:33:52.794608+00:00 app[web.1]: + 2 hidden modules
68% building modules 872/888 modules 16 active ...materier/lib/utils/isPrefixedValue.js
2016-10-29T19:33:52.794603+00:00 app[web.1]: [917] multi vendor 208 bytes {1} [built]
2016-10-29T19:33:52.794605+00:00 app[web.1]: Child extract-text-webpack-plugin:
65% building modules 657/705 modules 48 active ...ct-flexbox-grid/lib/components/Col.js
2016-10- 66% building modules 768/821 modules 53 active ...refixer/lib/utils/unprefixProperty.js
69% building modules 905/912 modules 8 active .../core-js/library/modules/_to-index.js
2016-10-29T19:33:52.794600+00:00 app[web.1]: vendor.9d66707b3af690baefd1.js 410 kB 1 [emitted] vendor
2016-10-29T19:33:52.794601+00:00 app[web.1]: app.437ada71305f4f7f06fa.css 25 kB 0 [emitted] app
2016-10-29T19:33:54.415735+00:00 app[web.1]:
2016-10-29T19:33:54.415747+00:00 app[web.1]: > Recipebook#1.0.0 start:prod /app
2016-10-29T19:33:54.415748+00:00 app[web.1]: > better-npm-run start:prod
2016-10-29T19:33:54.415749+00:00 app[web.1]:
2016-10-29T19:33:54.513444+00:00 app[web.1]: running better-npm-run in /app
2016-10-29T19:33:54.530984+00:00 app[web.1]: Executing script: start:prod
2016-10-29T19:33:54.535357+00:00 app[web.1]: to be executed: node ./index.js
2016-10-29T19:33:54.530987+00:00 app[web.1]:
2016-10-29T19:34:00.400261+00:00 app[web.1]: ==> � Listening at http://localhost:8080
2016-10-29T19:34:08.828406+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-29T19:34:08.828500+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-10-29T19:34:08.920786+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-29T19:34:08.921680+00:00 heroku[web.1]: State changed from crashed to starting
2016-10-29T19:34:08.936050+00:00 heroku[web.1]: Process exited with status 137
2016-10-29T19:34:18.932898+00:00 heroku[web.1]: Starting process with command `npm run start:production`
2016-10-29T19:34:23.973344+00:00 app[web.1]:
2016-10-29T19:34:23.973368+00:00 app[web.1]: > Recipebook#1.0.0 start:production /app
2016-10-29T19:34:23.973369+00:00 app[web.1]: > npm run build && npm run start:prod
2016-10-29T19:34:23.973369+00:00 app[web.1]:
2016-10-29T19:34:27.052893+00:00 app[web.1]:
2016-10-29T19:34:27.052904+00:00 app[web.1]: > Recipebook#1.0.0 build /app
2016-10-29T19:34:27.052905+00:00 app[web.1]: > npm run clean:build && better-npm-run build
2016-10-29T19:34:27.052906+00:00 app[web.1]:
2016-10-29T19:34:29.508764+00:00 app[web.1]:
2016-10-29T19:34:29.508780+00:00 app[web.1]: > Recipebook#1.0.0 clean:build /app
2016-10-29T19:34:29.508781+00:00 app[web.1]: > better-npm-run clean:build
2016-10-29T19:34:29.508782+00:00 app[web.1]:
2016-10-29T19:34:29.771274+00:00 app[web.1]: running better-npm-run in /app
2016-10-29T19:34:29.791323+00:00 app[web.1]: Executing script: clean:build
2016-10-29T19:34:29.791326+00:00 app[web.1]:
2016-10-29T19:34:29.797335+00:00 app[web.1]: to be executed: rimraf ./public/dist
2016-10-29T19:34:30.876988+00:00 app[web.1]: running better-npm-run in /app
2016-10-29T19:34:31.135328+00:00 app[web.1]: Executing script: build
2016-10-29T19:34:31.135338+00:00 app[web.1]:
2016-10-29T19:34:31.175397+00:00 app[web.1]: to be executed: webpack --progress --display-error-details --config ./tools/webpack/config.babel
2016-10-29T19:35:19.343215+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-10-29T19:35:19.343215+00:00 heroku[web.1]: Stopping process with SIGKILL
12% building modules 18/41 modules 23 active ...e_modules/react-router/lib/History.js
15% building modules 49/68 modules 19 active ...odules/regenerator-runtime/runtime.js
2016-10-29T19 17% building modules 64/111 modules 47 active ...e_modules/axios/lib/helpers/spread.js
2016-10-29T19:35:19.401700+00:00 22% building modules 108/125 modules 17 active ...de_modules/lodash-es/isPlainObject.js
2016-10-29T19:35:19.40170 24% building modules 124/390 modules 266 active ...s/core-js/library/fn/set-immediate.js
2016-10-29T19:35:19.401700+00: 29% building modules 165/406 modules 241 active ...ules/babel-runtime/helpers/extends.js
43% building modules 277/406 modules 129 active ...ules/babel-runtime/helpers/extends.js
22% building modules 108/181 modules 73 active ...les/core-js/modules/es6.math.log1p.js
56% building modules 384/412 modules 28 active ...ode_modules/lodash-es/isObjectLike.js
2016-10-29T19:35:19.40170 56% building modules 390/463 modules 73 active ...e_modules/core-js/modules/_classof.js
2016-10-29T19:35:19.401 22% building modules 108/238 modules 130 active ...s/core-js/modules/es6.regexp.match.js
2016-10-29T19:35:19.401700+00: 64% building modules 566/625 modules 59 active .../index.js!/app/src/constants/index.js
64% building modules 619/686 modules 67 active ...s/library/modules/web.dom.iterable.js
49% building modules 331/409 modules 78 active ...e_modules/react/lib/EventPluginHub.js
2016-10-29T19:35:19.401700+00:00 54% building modules 390/520 modules 130 active ..._modules/core-js/moes/_iter-create.js
36% building modules 221/406 modules 185 active ...ules/babel-runtime/helpers/extends.js
49% building modules 408/614 modules 206 active ...ules/core-js/library/modules/_core.js
23% building modules 113/345 modules 232 active ...odules/react/lib/ReactCurrentOwner.js
52% building modules 401/565 modules 164 active .../react/lib/ReactCompositeComponent.js
2016-10-29T19:35:19.401700+00:00 64% building modules 730/802 modules 72 active /app/node_modules/simple-assign/index.js
2016-10-29T19:35:19.4 66% building modules 607/641 modules 34 active ...node_modules/core-js/modules/_path.js
54% building modules 460/618 modules 158 active ...abel-runtime/core-js/object/assign.js
2016-10-29T19:35:19.401700+0 60% building modules 516/618 modules 102 active ...abel-runtime/core-js/object/assign.js
22% building modules 108/294 modules 186 active ...les/core-js/modules/es7.math.imulh.js
2016-10-29T19:35 65% building modules 707/768 modules 61 active ...odules/axios/lib/core/enhanceError.js
66% building modules 768/821 modules 53 active ...refixer/lib/utils/unprefixProperty.js
66% building modules 690/728 modules 38 active /app/node_modules/fbjs/lib/isTextNode.js
65% building modules 657/705 modules 48 active ...ct-flexbox-grid/lib/components/Col.js
2016-10-29T19:35 66% building modules 800/846 modules 46 active ...ixer/lib/static/plugins/transition.js
66% building modules 828/875 modules 47 active ...react-addons-create-fragment/index.js
68% building modules 869/887 modules 18 active ...prefixer/lib/utils/isPrefixedValue.jsError waiting for process to terminate: No child processes
2016-10-29T19:35:19.532075+00:00 heroku[web.1]: Process exited with status 22
2016-10-29T19:35:19.533651+00:00 heroku[web.1]: State changed from starting to crashed
2016-10-29T19:41:05.532116+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-retreat-75182.herokuapp.com request_id=f7e80c38-c84b-4f75-9478-59d782c1e112 fwd="207.244.90.77" dyno= connect= service= status=503 bytes=
2016-10-29T19:41:09.449918+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-retreat-75182.herokuapp.com request_id=93c05f33-7ec5-4b5f-8409-f218c159a020 fwd="207.244.90.77" dyno= connect= service= status=503 bytes=
2016-10-29T19:41:15.280404+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-retreat-75182.herokuapp.com request_id=3b8fd867-6383-4a6a-bf01-b3e379f05225 fwd="207.244.90.77" dyno= connect= service= status=503 bytes=
2016-10-29T19:41:16.426158+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-retreat-75182.herokuapp.com request_id=1dd69267-6fcc-4ab4-ad0e-00a985606a18 fwd="207.244.90.77" dyno= connect= service= status=503 bytes=
The problem is you cannot use better-npm-run directly in the CLI.
You need to use shell-exec and specify the command.
Check the official documentation: https://www.npmjs.com/package/better-npm-run#cli-commands
[EDIT]
Move better-npm-run to dependencies or make heroku to install devDependencies
Refer: https://devcenter.heroku.com/articles/nodejs-support#devdependencies
Heroku binds the port number dynamically so you need to use process.env.PORT to get the dynamically allocated port. Something similar to this.
Hope this helps!

Categories