Heroku typescript deployment issue - node.js

I am trying to deploy a nodejs application (which also uses typeORM) written in typescript to heroku.
My package.json devDependencies look like the following:
"devDependencies": {
"#types/cors": "^2.8.9",
"#types/node": "^8.10.66",
"nodemon": "^2.0.6",
"ts-node": "3.3.0",
"typescript": "3.3.3333"
},
and my scripts section look like so:
"scripts": {
"start": "node build/server.js",
"build": "tsc",
"postinstall": "npm run build",
"dev": "nodemon --exec ts-node src/server.ts"
}
I've set build to "tsc" so that Heroku compiles the typescript and specified the files to go inside the build folder, however when starting the server and running the tail log using heroku logs --tail, it seems to be trying to use my .ts files and it gives the error like below:
2021-01-03T22:30:28.445473+00:00 app[web.1]: Error: /app/src/entities/User.ts:1
2021-01-03T22:30:28.445474+00:00 app[web.1]: import { Person } from "./Person";
2021-01-03T22:30:28.445475+00:00 app[web.1]: ^^^^^^
2021-01-03T22:30:28.445475+00:00 app[web.1]:
2021-01-03T22:30:28.445479+00:00 app[web.1]: SyntaxError: Cannot use import statement outside a module
2021-01-03T22:30:28.445480+00:00 app[web.1]: at wrapSafe (internal/modules/cjs/loader.js:915:16)
2021-01-03T22:30:28.445480+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:963:27)
2021-01-03T22:30:28.445481+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
2021-01-03T22:30:28.445482+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:863:32)
2021-01-03T22:30:28.445482+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:708:14)
2021-01-03T22:30:28.445483+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:887:19)
2021-01-03T22:30:28.445483+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:74:18)
2021-01-03T22:30:28.445484+00:00 app[web.1]: at /app/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:41:39
2021-01-03T22:30:28.445484+00:00 app[web.1]: at Array.map (<anonymous>)
2021-01-03T22:30:28.445485+00:00 app[web.1]: at Object.importClassesFromDirectories (/app/node_modules/typeorm/util/DirectoryExportedClassesLoader.js:41:10)
2021-01-03T22:30:28.445704+00:00 app[web.1]: Cannot use import statement outside a module
Also note that i don't have a Procfile as it handles it by default.
Is there some other information i am missing to include?
Thanks

Related

Jest in Node JS

I installed jest on my node js project with : npm install --save-dev jest.
I added jest in the script of package.json:
"scripts": {
"start": "node app/index.js",
"dev": "nodemon app/index.js",
"test": "jest"
}
I try launching jest with the commande: npm run test but I always get this error:
PS P:\Projets Angular\dblogwebapp\back-end> npm run test
> back-end#1.0.0 test
> jest
Error: EPERM: operation not permitted, realpath 'myPath\back-end'
at Function.realpathSync.native (node:fs:2550:3)
at tryRealpath (myPath\back-end\node_modules\jest-util\build\tryRealpath.js:26:39)
at Object.<anonymous> (myPath\back-end\node_modules\jest-resolve\build\resolver.js:124:49)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (myPath\back-end\node_modules\jest-resolve\build\index.js:9:40)
Can anyone help me plz. thanks

Error: Cannot find module \node_modules\sqlite3\lib\binding\electron-v8.0-win32-x64\node_sqlite3.node'

I have trouble with installing sqlite3 in electron 8.1
I got following errors
Error: Cannot find module 'D:\TASK(2020.1.1~)\AMS\node_modules\sqlite3\lib\binding\electron-v8.1-win32-x64\node_sqlite3.node'
Require stack:
- D:\TASK(2020.1.1~)\AMS\node_modules\sqlite3\lib\sqlite3.js
- D:\TASK(2020.1.1~)\AMS\main.js
- D:\TASK(2020.1.1~)\AMS\node_modules\electron\dist\resources\default_app.asar\main.js
-
at Module._resolveFilename (internal/modules/cjs/loader.js:798:15)
at Function../lib/common/reset-search-paths.ts.Module._resolveFilename (electron/js2c/browser_init.js:7595:16)
at Module._load (internal/modules/cjs/loader.js:691:27)
at Module._load (electron/js2c/asar.js:717:26)
at Function.Module._load (electron/js2c/asar.js:717:26)
at Module.require (internal/modules/cjs/loader.js:853:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (D:\TASK(2020.1.1~)\AMS\node_modules\sqlite3\lib\sqlite3.js:4:15)
at Module._compile (internal/modules/cjs/loader.js:968:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:986:10)
I installed npm install sqlite3 --build-from-source --runtime=electron --target=8.0.2 --dist-url=https://atom.io/download/electron
But no luck. Please help me.
Finally, I figured out and solved.
needed to followings
"scripts": {
"start": "electron .",
"postinstall": "electron-builder install-app-deps",
"package": "electron-packager . --production"
},
after that, npm run postinstall
it worked for me.

Understanding Heroku bcrypt errors in log when deploying Nodejs app

I am trying to deploy my node.js app to Heroku. It works perfectly fine locally, but when I try to deploy it I keep getting this:
2017-12-12T17:32:18.220591+00:00 app[web.1]: > ev#1.0.0 start /app
2017-12-12T17:32:18.220592+00:00 app[web.1]: > node app.js
2017-12-12T17:32:18.220592+00:00 app[web.1]:
2017-12-12T17:32:18.898850+00:00 heroku[web.1]: Process exited with status 1
2017-12-12T17:32:18.910740+00:00 heroku[web.1]: State changed from starting to crashed
2017-12-12T17:32:18.819322+00:00 app[web.1]: module.js:664
2017-12-12T17:32:18.819338+00:00 app[web.1]: return process.dlopen(module, path._makeLong(filename));
2017-12-12T17:32:18.819339+00:00 app[web.1]: ^
2017-12-12T17:32:18.819339+00:00 app[web.1]:
2017-12-12T17:32:18.819340+00:00 app[web.1]: Error: /app/node_modules/bcrypt/lib/binding/bcrypt_lib.node: invalid ELF header
2017-12-12T17:32:18.819341+00:00 app[web.1]: at Object.Module._extensions..node (module.js:664:18)
2017-12-12T17:32:18.819342+00:00 app[web.1]: at Module.load (module.js:554:32)
2017-12-12T17:32:18.819342+00:00 app[web.1]: at tryModuleLoad (module.js:497:12)
2017-12-12T17:32:18.819343+00:00 app[web.1]: at Function.Module._load (module.js:489:3)
2017-12-12T17:32:18.819343+00:00 app[web.1]: at Module.require (module.js:579:17)
2017-12-12T17:32:18.819344+00:00 app[web.1]: at require (internal/module.js:11:18)
2017-12-12T17:32:18.819344+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/bcrypt/bcrypt.js:6:16)
2017-12-12T17:32:18.819345+00:00 app[web.1]: at Module._compile (module.js:635:30)
2017-12-12T17:32:18.819345+00:00 app[web.1]: at Object.Module._extensions..js (module.js:646:10)
2017-12-12T17:32:18.819345+00:00 app[web.1]: at Module.load (module.js:554:32)
2017-12-12T17:32:18.819346+00:00 app[web.1]: at tryModuleLoad (module.js:497:12)
2017-12-12T17:32:18.819346+00:00 app[web.1]: at Function.Module._load (module.js:489:3)
2017-12-12T17:32:18.819346+00:00 app[web.1]: at Module.require (module.js:579:17)
2017-12-12T17:32:18.819347+00:00 app[web.1]: at require (internal/module.js:11:18)
2017-12-12T17:32:18.819347+00:00 app[web.1]: at Object.<anonymous> (/app/models/users.js:3:14)
2017-12-12T17:32:18.819347+00:00 app[web.1]: at Module._compile (module.js:635:30)
2017-12-12T17:32:18.827094+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2017-12-12T17:32:18.827465+00:00 app[web.1]: npm ERR! errno 1
2017-12-12T17:32:18.828807+00:00 app[web.1]: npm ERR! ev#1.0.0 start: `node app.js`
2017-12-12T17:32:18.828992+00:00 app[web.1]: npm ERR! Exit status 1
2017-12-12T17:32:18.829148+00:00 app[web.1]: npm ERR!
2017-12-12T17:32:18.829260+00:00 app[web.1]: npm ERR! Failed at the ev#1.0.0 start script.
2017-12-12T17:32:18.829357+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-12-12T17:32:18.834511+00:00 app[web.1]:
2017-12-12T17:32:18.834634+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2017-12-12T17:32:18.834782+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2017-12-12T17_32_18_830Z-debug.log
I have done npm install and npm install bcrypt again but the error persists. From my understanding of the log I think it is clear the error relates to bcrypt?
Here is my package.json file:
{
"name": "ev",
"version": "1.0.0",
"description": "search",
"main": "app.js",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"bcrypt": "^1.0.3",
"body-parser": "*",
"express": "*",
"jsonwebtoken": "^8.1.0",
"mongoose": "*"
},
"author": "My Name",
"license": "ISC"
You can use a pure JS version of bcrypt library.
Something like this
https://github.com/dcodeIO/bcrypt.js
This doesnt have any native dependency and should work perfectly.
We faced a lot difficulties in deploying apps with native dependencies to heroku and other cloud platform and we had to swap some of the libraries like bcrypt with pure js versions.

Heroku Deploy Error: Cannot find module './errors/cast'

I built my app using yeoman angular-fullstack generator and then modified for my own purposes. I built the dist folder to deploy to heroku using yo angular-fullstack:deploy heroku. It creates a new heroku app for me and when I cd into the dist folder and git push heroku master everything works great.
I want to be able to add my existing heroku app to the deployment process for this dist folder so I followed this post How to link a folder with an existing Heroku app. I'm able to then deploy to my own app with a different remote name than heroku.
I keep getting the same error when it starts to run on heroku. I can't figure out why the exact same code runs fine on the app created for me but not my existing app. It's almost like I need to clear the node_modules and push again?
2014-02-21T04:43:51.989439+00:00 app[web.1]: module.js:340
2014-02-21T04:43:51.996351+00:00 app[web.1]: Error: Cannot find module './errors/cast'
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2014-02-21T04:43:51.991555+00:00 app[web.1]: throw err;
2014-02-21T04:43:51.991785+00:00 app[web.1]: ^
2014-02-21T04:43:51.996351+00:00 app[web.1]: at require (module.js:380:17)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Module.require (module.js:36 4:17)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Module._compile (module.js:456:26)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/mongoose/lib/error.js:32:27)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-02-21T04:43:51.996351+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10)
2014-02-21T04:43:51.996560+00:00 app[web.1]: at Module.require (module.js:364:17)
2014-02-21T04:43:53.457214+00:00 heroku[web.1]: State changed from starting to crashed
Here is my packages.json from the dist folder
{
"name": "myapp",
"version": "1.0.0",
"dependencies": {
"express": "~3.4.3",
"lodash": "~2.4.1",
"mongoose": "~3.5.5",
"mongoose-unique-validator": "~0.3.0",
"connect-mongo": "~0.4.0",
"passport": "latest",
"passport-local": "latest",
"passport-facebook": "latest",
"passport-twitter": "latest",
"passport-google": "latest",
"ejs": "~0.8.4"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test"
}
}
The issue is almost certainly that you haven't checked in all the files you need. If you can't see the problem in your git repository, try running heroku run bash and using cd, ls, and more to look around what's getting deployed to Heroku and see what is missing.
Your problem is likely that you have require('./errors/cast') but have not checked in a cast file.
Update:
The other likelihood is that you checked in ./errors/Cast on OS X which is case insensitive, but the file can't be found on Linux which is case sensitive.

Node.js app running on heroku - can't find module ./http

I'm going crazy trying to figure this out. I have a node.js app using Express and MongoDB (mongoose). It runs perfectly fine locally. I deployed it to heroku seemingly without a problem, but when I try to actually launch the app it crashes. The heroku log says this:
macbook-pro-4:FF_Courtney cmitchell$ heroku logs
2012-10-29T19:31:27+00:00 heroku[web.1]: State changed from crashed to starting
2012-10-29T19:31:30+00:00 heroku[web.1]: Starting process with command `node web.js`
2012-10-29T19:31:31+00:00 app[web.1]:
2012-10-29T19:31:31+00:00 app[web.1]: module.js:340
2012-10-29T19:31:31+00:00 app[web.1]: throw err;
2012-10-29T19:31:31+00:00 app[web.1]: Error: Cannot find module './http'
2012-10-29T19:31:31+00:00 app[web.1]: ^
2012-10-29T19:31:31+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2012-10-29T19:31:31+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2012-10-29T19:31:31+00:00 app[web.1]: at Module.require (module.js:362:17)
2012-10-29T19:31:31+00:00 app[web.1]: at require (module.js:378:17)
2012-10-29T19:31:31+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/express/node_modules/connect/lib/connect.js:13:18)
2012-10-29T19:31:31+00:00 app[web.1]: at Module._compile (module.js:449:26)
2012-10-29T19:31:31+00:00 app[web.1]: at Object.Module._extensions..js (module.js:467:10)
2012-10-29T19:31:31+00:00 app[web.1]: at Module.load (module.js:356:32)
2012-10-29T19:31:31+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2012-10-29T19:31:31+00:00 app[web.1]: at Module.require (module.js:362:17)
2012-10-29T19:31:32+00:00 heroku[web.1]: Process exited with status 1
I have a package.json file with my dependencies:
{
"name": "favorite-failure",
"version": "0.0.1",
"dependencies": {
"express": "2.5.6",
"ejs" : "latest",
"mongoose" : "3.3.1",
"request" : "2.11.4",
"moment" : "1.7.2",
"mongodb" : "0.9.6-7",
"connect-mongodb": ">= 1.1.3"
},
"engines": {
"node": ">= 0.8.12",
"npm": ">= 1.1.49"
}
}
I'm a bit new to this, so any help would be greatly appreciated. Thanks!

Resources