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.
Related
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
I am trying to execute nodejs code to invoke AWS API using aws-api-gateway-client module. Code workes perfectly in my laptop however when deployed to TEST server which has latest nodejs and aws npm module installed.
var apigClientFactory = require('aws-api-gateway-client')
Path Npm modules are installed:
C:\Program Files\nodejs\node_modules\npm\node_modules
Output
''' internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'aws-api-gateway-client'
Require stack:
- C:\Myfolder\agent\scripts\NodeJSAWSConnector\APINetworks.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Module.require (internal/modules/cjs/loader.js:1042:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (C:\ServiceNow\foggydev\agent\scripts\NodeJSAWSConnector\APINetworks.js:8:25)
at Module._compile (internal/modules/cjs/loader.js:1156:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
at Module.load (internal/modules/cjs/loader.js:1000:32)
at Function.Module._load (internal/modules/cjs/loader.js:899:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\MyFolder\\agent\\scripts\\NodeJSAWSConnector\\APINetworks.js'
]
}
'''
Please advise on the above issue.
Update 2:
package.json file has entry
"dependencies": {
"JSONStream": "^1.3.5",
"abbrev": "~1.1.1",
"ansicolors": "~0.3.2",
"ansistyles": "~0.1.3",
"aproba": "^2.0.0",
"archy": "~1.0.0",
"aws-api-gateway-client": "^0.3.3",
"aws-sdk": "^2.656.0",
"bin-links": "^1.1.7",
"bluebird": "^3.5.5",
"byte-size": "^5.0.1",
"cacache": "^12.0.3",
"call-limit": "^1.1.1",
"chownr": "^1.1.4",
"ci-info": "^2.0.0",
"cli-columns": "^3.1.2",
"cli-table3": "^0.5.1",
Also, aws-api-gateway-client is installed at C:\Program Files\nodejs\node_modules\npm\node_modules
Your app is in C:\ServiceNow\foggydev\agent\scripts\NodeJSAWSConnector\APINetworks.js
node_modules are in: C:\Program Files\nodejs\node_modules\npm\node_modules
Seems like You've installed aws-api-gateway-client globally (since You're saying that node_modules folder is in different place)
Steps to check and solve:
1) check package.json file if it exists in dependencies,
2) make sure in Your test server aws-api-gateway-client exists in node_modules folder,
3) do npm i --save aws-api-gateway-client to install it in node_modules folder relative to Your project, which will also add that module to dependencies in package.json
4) deploy to test server again with updated packge.json
Everything was working until I did a npm install on my project folder.
I am running macOS Sierra 10.12.5, node.js v8.2.1, npm v5.3.0
What I have tried:
uninstalling node/npm and reinstalling
npm install -g browserify
npm insatll browserify on my project folder
reinstall KeystoneJS generator
my package.json
{
"name": "site-name",
"version": "0.0.0",
"private": true,
"dependencies": {
"keystone": "4.0.0-beta.5",
"lodash": "^4.13.1",
"consolidate": "0.14.5",
"nunjucks": "3.0.0",
"node-sass": "4.5.0",
"node-sass-middleware": "0.11.0",
"dotenv": "4.0.0",
"async": "2.1.4",
"express-sslify": "1.2.0"
},
"devDependencies": {
"eslint": "3.15.0",
"eslint-config-keystone": "3.0.0",
"eslint-plugin-react": "^5.1.1"
},
"scripts": {
"lint": "eslint .",
"start": "node keystone.js"
}
}
Here is the output in terminal
node keystone
module.js:487
throw err;
^
Error: Cannot find module './browserify'
at Function.Module._resolveFilename (module.js:485:15)
at Function.Module._load (module.js:437:25)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/Tyler/Desktop/Forge_Fitness_Site/models/node_modules/sha.js/bin.js:3:18)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Module.require (module.js:513:17)
at require (internal/module.js:11:18)
at /Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:42:23
at Array.forEach (native)
at importer (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:32:26)
at /Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:36:22
at Array.forEach (native)
at importer (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:32:26)
at /Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:36:22
at Array.forEach (native)
at importer (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/lib/core/importer.js:32:26)
at Keystone.import (/Users/Tyler/Desktop/Forge_Fitness_Site/node_modules/keystone/index.js:176:42)
at Object.<anonymous> (/Users/Tyler/Desktop/Forge_Fitness_Site/keystone.js:41:16)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
Well, I fixed the issue, not exactly sure how it happened but somehow I ended up with two node_modules folders in my project directory. Deleting the second one fixed my issue.
I'm having issues deploying to Heroku. Got it running locally after i had the same error by simply rm -f node_modules and then reinstalling them with npm install. But when i deploy to heroku the error keeps occurring. Even went in with bash to perform the same steps.
I then used npm shrinkwrap and noticed aws-sdk has a dependency on lodash vs 3.5.0 <3.6.0. So i set the lodash version in my package.json accordingly.
It all still runs locally but keeps crashing on heroku.
Node v5.0.0
NPM v3.3.6
"dependencies": {
"aws-sdk": "^2.6.6",
"bluebird": "^3.4.6",
"body-parser": "^1.15.2",
"express": "^4.14.0",
"goosepage": "0.0.1",
"lodash": "^3.5.0"
}
Additional heroku log
Error: Cannot find module 'lodash/object/assign'
Function.Module._resolveFilename (module.js:337:15)
Function.Module._load (module.js:287:25)
Module.require (module.js:366:17)
require (module.js:385:17)
Object.<anonymous> (/app/node_modules/xmlbuilder/lib/index.js:5:12)
Object.<anonymous> (/app/node_modules/xmlbuilder/lib/index.js:14:4)
Module._compile (module.js:425:26)
Object.Module._extensions..js (module.js:432:10)
Module.load (module.js:356:32)
Function.Module._load (module.js:311:12)
Module.require (module.js:366:17)
require (module.js:385:17)
Object.<anonymous> (/app/node_modules/aws-sdk/lib/xml/builder.js:2:15)
Module._compile (module.js:425:26)
Object.Module._extensions..js (module.js:432:10)
Module.load (module.js:356:32)
Turns out Heroku had a Buildpack that was caching node_modules. Turning off caching didnt help so i had to use the heroku plugin to clear the cached which worked.
https://github.com/heroku/heroku-repo
heroku repo:purge_cache -a appname
The following allegedly should also work incase the above doesn't
heroku config:set NODE_MODULES_TRUE=false
Error: Cannot find module 'once'
at Function.Module._resolveFilename (module.js:337:15)
at Function.Module._load (module.js:287:25)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/usr/local/lib/node_modules/nodemon/node_modules/update-notifier/node_modules/latest-version/node_modules/package-json/node_modules/got/node_modules/duplexify/node_modules/end-of-stream/index.js:1:74)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
I'm getting this error when I try running my server.js with nodemon. I looked in my node_modules folder and there is a 'once' folder in there. I tried
rm -rf node_modules
npm install
to remove the entire node_modules folder and reinstall but it didn't work. I also did
npm install --save once
and still didn't work.
This is package.json
{
"name": "FullMean_Friends",
"version": "0.0.1",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "latest",
"express": "~4.2.0",
"mongoose": "latest"
}
}