Deploying NodeJS/Babel/Grunt app on Heroku - node.js

I'm trying to deploy my project on Heroku. I've been able to heroku open the app and see it but I get a 404 on my bundle.js. The app is on github here. The app is on heroku here.
I've tried making sure my dependencies are all there regarding babel, babelify, grunt, etc. But I must be still missing something.
I don't get any errors after my git push heroku but I still get my 404.

I am able to recreate this locally as well. This is what I get when I run your postinstall script code:
$ npm run postinstall
> ncps-mms#0.0.0 postinstall ncps-mms
> gulp transpile --gulpfile client/gulpfile.babel.js
[00:18:43] Requiring external module babel-register
[00:18:43] Working directory changed to ncps-mms/client
(node:30276) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
[00:18:43] Using gulpfile ncps-mms/client/gulpfile.babel.js
[00:18:44] Starting 'transpile'...
Error: Cannot find module './controllers/members-detail-controller' from 'ncps-mms/client/src'
[00:18:44] Finished 'transpile' after 184 ms
I see this error:
Error: Cannot find module './controllers/members-detail-controller' from 'ncps-mms/client/src'
The members-detail-controller is missing - See: https://github.com/gh0st/ncps-mms/tree/master/client/src/controllers.
If I comment out the following lines, https://github.com/gh0st/ncps-mms/blob/master/client/src/app.js#L4 and https://github.com/gh0st/ncps-mms/blob/master/client/src/app.js#L15 then run npm run postinstall again, the gulp tasks run without errors. I am then able to start the server without the 404's on bundle.js.

Related

Can't run my vite and sveltekit non-js module files deprecated

I am using seveltkit and vite when I run with npm run devthen it give me a
Localhost localhost:5173 when I go to it give me this
First it was give me 500|error then I wrote some code and this error come back again it was here before the 500|error

How to deploy Nuxt.js to Elastic Beanstalk?

I am very new to AWS and i have been following the tutorials out there but couldn't find the answer. So, what i did was i created simple nuxt application, no changes to the framework's script or anything. I set my elastic beanstalk to run node.js settings. and then i tried to deploy my /dist folder(using nuxt build) with the application's json folder as told by every tutorials. but it gives me this this is what it looks on my webpage
I think i have something wrong with which folders i deploy or do i have to actually deploy via the aws CLI, would that make a difference at all?
eb log :
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/.npm/_logs/2019-09-29T16_00_28_939Z-debug.log
> portfolio#1.0.0 start /var/app/current
> cross-env NODE_ENV=production node server/index.js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/var/app/current/server/index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
The nodejs logs indicate to me that there is an issue with the build, an issue with how it's zipped, or an issue with your start command.
The most common is incorrectly zipping source files
When you create a ZIP file in Mac OS X Finder or Windows Explorer, make sure you zip the files and subfolders themselves, rather than zipping the parent folder.
In other words, do not right click the dist folder and click "zip", select all the files and folders (including hidden ones) and zip those. Elastic beanstalk, and many other AWS services, expect the zip to unpack into a flat structure, and not contain the parent folder when unzipped.
If this does not solve your problem, make sure you're zipping the correct folder. Try deleting your .nuxt and /dist folders, and running npm run build locally. The folder that is produced (defaults to .nuxt) is the folder whose contents need to be zipped.
The reason it is throwing that error is because your launch command starts with cross-env. When it sees that it tries to run the globally installed package cross-env but it is not available globally, so it throws that error. There are a few possible ways to address this:
The easiest is to just change the start command to use a relative path to the locally installed version of cross-env, so your command should look something like this:
node_modules/cross-env/src/bin/cross-env.js node server/index.js
You might also try adding npx to the front of your command, like so:
npx cross-env NODE_ENV=production node server/index.js
This should work but I have found that sometimes I get errors with specific packages, from what I can tell it is a bug with npx but I haven't had time to look into it. Notably I did see this bug with a nuxt js app specifically so you might too, however I was using the nuxt cli which you are not.
The third option is you could look into installing the package globally using ebextensions. In my work I haven't come across a situation where that has been necessary.

Node package dependencies on IBM Cloud Foundry - require/module is not defined (Package not loading)

I am working on an application via the toolchain tool on IBM Cloud and editing the code via the Eclipse Orion IDE. As I am not accessing this through my local cli, my understanding is that in order to so call npm install {package}, I would just need to include the package in the package.json file under dependencies and require it in my app. However, when I load the application, I get the require is not defined indicating that the package has not been installed. Moreover, the require() is being used in the app.js file with the application being launched but not from files in my public directory.
After playing around further, it seems it might have to do with the way the directory tree is being traced as the error is only thrown in subdirectories. For example, require('express') works in app.js which is in the main directory ./ but fails when it is called in test.js in ./subdirectory/test.js. I feel like I'm missing something painfully simple like configuration of endpoint or something.
I've been searching around but I can't seem to find how to get the packages loaded, preferably without using the cli. Appreciate any pointers. Thanks!
Update: After playing around further, I am also getting module is not defined error when trying to require from another file in the same directory. For example module.exports = 'str' returns this error. While trying to require('./file') returns the require is not defined. It might have to do with how node is wrapping the functions?
Update 2: Tried "start": "npm install && node app.js" in package.json but no luck. Adding a build stage which calls npm install before deployment also does not work
Update 3: After adding npm install build stage, I am able to see that the dependencies have been successfully built via the logs. However, the require is not defined error still persists.
Update 4: Trying npm install from my CLI doesn't work as well even though all packages and dependencies are present
Update 5: Running cf restage or configuring cache via cacheDirectories does not work as well
Opened a related question regarding deployment here
Found out my confusion was caused due to me not realizing that require() cannot be used on the client side unless via tools such as Browserify.

Webpack Node.js on Heroku Deployment Error

I built an application with React/Node.js/PostgreSQL Webpack and now attempting to deploy on heroku.
Everything works perfectly on my localhost, but it doesn't serve on Heroku. error message image on Heroku -
I've tried multiple buildpacks to make it happen, but it still gives me the same result, and I cannot figure out the problem as my logs don't seem to have any issues.
Any ideas would be greatly appreciated.
Here is the link to my repo https://github.com/strongharris/Edu-it
To Run it:
npm install ->
npm run build ->
npm start
The problem here is with your code. I tried to deploy a copy of your project to Heroku, and it's giving me an error because config.connection does not exist when you use it in a conditional.
Here's the error:
(These logs were retrieved by me deploying the Heroku app, then running heroku logs to view the log output.)
As you can see, the error is here: https://github.com/strongharris/Edu-it/blob/master/server/database/database_config.js#L9
You'll need to re-write this code so it runs properly without that variable.

why babel stores .babel.json in USERPROFILE path

I'm running a nodejs app on azure web apps and i'm trying to integrate babel using npm in it. The problem is that babel is trying to acccess a file at
%USERPROFILE%
named .babel.json, a file that doesn't exist. This is most likely installed by:
npm install -g babel
On azure web apps, i can't seem to find it at all (even after running npm install -g babel in kudu for the site).
I copied the file in %USERPROFILE% myself to %USERPROFILE% using kudu but on web app restart the file disappears.
Is there a way to make babel work on web apps?
UPDATE
I did omit some things. The error appeared when i tried load babel/register.
require('babel/register')({
optional: ["es7.asyncFunctions"]
});
and the actual error i see in the streaming logs is
Application has thrown an uncaught exception and is terminated: Error:
ENOENT, no such file or directory 'D:\local\UserProfile.babel.json'
at Object.fs.openSync (fs.js:438:18)
at Object.fs.writeFileSync (fs.js:977:15)
at save (D:\home\site\wwwroot\node_modules\babel\node_modules\babel-core\lib\api\register\cache.js:35:19)
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
the project is on Github
I had this same problem, solved it by disabling the babel cache by setting the environment variable BABEL_DISABLE_CACHE=1 in my Application settings.
You can read more about the babel cache here:
https://babeljs.io/docs/usage/require/#environment-variables
You change the store location of .babel.json by BABEL_CACHE_PATH
I think its better than disable caching
BABEL_CACHE_PATH=any_writable_and_exist_dir/babel.cache.json
The error appeared when i tried load babel/register.
Please check the Cache.js at (..\node_modules\babel\node_modules\babel-core\lib\api\register\Cache.js) to see if there is any babel cache path definition, e.g.
process.env.BABEL_CACHE_PATH || _path2["default"].join(_homeOrTmp2["default"], ".babel.json");
If you leverage this kind of variables, it's needed to have BABEL_CACHE_PATH app setting key and value of ./cache otherwise anything with babel wouldn't work on azure. Please refer to http://blog.syntaxc4.net/post/2012/07/26/accessing-app-settings-configured-in-microsoft-azure-web-sites-using-php-and-node-js.aspx in case you wanna know the details of accessing app settings in Azure web site using node.js.
Should you have any further concern, please feel free to let us know.
I create a nodejs app from Azure Gallery "Node JS Empty Web app" and run the command npm install -g babel in Kudu. I tried to reproduct your issue, but failed that the babel is not trying to access the file .babel.json at %USERPROFILE%.
On Azure, the npm global modules will be installed into the path "D:\local\AppData". When you restart the WebApp, the node global modules will be deleted.
If you have to use the node global modules, you can configure a startup task for a node web role to install node modules when web role start up in Cloud Service. Please refer to https://azure.microsoft.com/en-us/documentation/articles/cloud-services-startup-tasks/.
Normally, installed node modules by using npm install <module-name> at the path "wwwroot" of Kudu Debug Console on Azure Web Apps.
I tried to install the babel module at the path "wwwroot" and run the command node_module\.bin\babel, and write a file include the code require('babel') to run it successfully. It works fine.
Best Regards.

Resources