Unexpected token export when deploying a MERN app to digitalocean - node.js

I'm trying to deploy a MERN app to a digital ocean droplet. I have used nodemon and concurrently to run my app through "npm run dev". Everything works fine when running in my local machine, but when I git clone the project to the droplet and try to npm run dev to run the app on the remote server, I get:
SyntaxError: Unexpected token export
I even removed the middleware where the error happens and tried to run again, but the error happened somewhere else in my code. I've stuck in this since yesterday. Do you have any idea?

You should check your Node version on the server. Most probably it's older and you're using ES6 exports.
If you got the right version that supports ES6, then you should make sure you've enabled that (as CommonJS is the default option). From the docs:
Files ending in .mjs.
Files ending in .js when the nearest parent package.json file contains a top-level "type" field with a value of "module".
Strings passed in as an argument to --eval, or piped to node via STDIN, with the flag --input-type=module.

Related

PM2 starting Meteor App not working

I have in one Digital Ocean Linux Ubuntu 16.041 droplet an instance of a Meteor app. Moreover, I installed Node.js version of 4.4.0
I created the respective bundle on the path ~/MyApplication/bundle. As a matter of fact, I automated with a config.json file the execution which its body contains the following code:
My main.js file is created from the Meteor build --directory ~/myDirectory/ command and contains the following code:
process.argv.splice(2, 0, 'program.json');
process.chdir(require('path').join(__dirname, 'programs', 'server'));
require('./programs/server/boot.js');
That being said, I run my application with pm2 through the config JSON file with pm2 start config.json
It starts the application, but several ms afterwards it is errored. The log error show the following exception regarding the typo, but seems the mainjs file is created fine. Any suggestions to solve it?
In the end, I had to update the node version in the server from 4.4.0 to 8.9.1. After doing that changes, I also had to install the dependencies within the bundle/programs/server/ using npm install

Meteor Buildpack for Cloud Foundry

I'm trying to get the meteor buildpack for cloud foundry running and its almost there except right at the end I get a node command not found error. I've confirmed that during the build I can run node and npm version commands. I get no errors until the instance fails to start.
Node gets installed into a folder called .vendor. I'm new to linux but is it possible that this folder isn't accessible at some point for some reason because of the dot? Meteor gets installed into a folder called vendor so I will try installing node there too. Can anyone think of something else to try?? I also tried changing the node folder to 777 in case it was a permissions thing. Far as I can tell the PATH variable is setup correctly.
I got the app deployed by converting to a node app and using the node buildpack but i'd prefer to use the meteor buildpack.

Cannot deploy node.js app on GAE

I'm having trouble deploying my node.js app to GAE.
It's a simple app that connects to my Firebase and updates a value. Just to get started.
Whenever I try to deploy the app it fails. Runs fine locally.
I deleted my project and started a fresh one, and deployed the default 'hello-world' app after downloading the zip and it worked fine.
I installed firebase on the project via the cloud shell.
Added
var Firebase = require("firebase");
to the app.js file and it no longer deploys.
I am new to GAE and cannot understand why it won't deploy. I feel like if i'm having trouble just including firebase in an app, I'm in for a tough time.
This is the error I get. The only think I have added to the original hello-world app is the firebase dependency. I remove that and it deploys fine again.
Updating service [default]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [13] Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).
Any help would be greatly appreciated.
I fixed the issue by installing the firebase npm on my local machine again. I noticed when I was installing it on the server (even with --save) it wasn't updating the package.json file for some reason and it hadn't updated it locally either. But it still ran on my local machine without the package mentioning a firebase dependency. Not sure why that would be the case.
It seems to be working now.
Before you can require the "firebase" package you need to install it.
To install the latest version of the package using the command line:
Navigate to the project root directory
Run npm install --save firebase
You will now have Firebase, and all the packages that it depends on, installed in your app.
The --save argument makes the command save the package installation configuration to the package.json file, so that the package is installed when you run the npm install command to set up the project on another computer, or when your app is deployed to Google App Engine.
You can check the logs for error. To check it goto your project at google console (console.cloud.google.com) and then Menu-> Logs.
Usually this error comes when app couldn't start while deploying. 1st check if the app local environment. If it is working fine then check if any environment variable is required to set and not set properly on cloud.

Adding a custom Node JS version to openshift doesn't work for my app

I have written an application which needs Node.js >= 4.2.6
I'm using the OpenShift service and the default Node.Js version is 0.10. Installing this https://github.com/ryanj/nodejs-custom-version-openshift is supposed to resolve this problem. So I followed the instructions and created a new application using:
rhc app create nodeapp nodejs --from-code=git://github.com/ryanj/nodejs-custom-version-openshift.git
So far so good. Next step - copy my project to the cloned git repository. Here's where I'm unsure if my approach is right (new to Node js). Because the cloned git already has a JSON package and because my app has its own JSON package in its root directory, I enriched the JSON package that came with nodejs-custom-version-openshift.git with my dependencies and set the engines to 4.2.6. The main is set to server.js. To run my app, I'm using "var variable = require('./myapp-master/test/test');" as the last line in my server.js. I copy the content of my app to the cloned repository (including node modules etc.) careful not to overwrite any existing config files like the JSON Package and then I use git push. The node version is installed properly according to the logs (upon build), servers.js is executed and it invokes my test.js. I can see in the app logs (app-root/logs) that test.js throws a specific error that indicates that the node js version is not >= 4.2.6.
When I log-in with PUTTY and write node -v, I get 4.2.6. When I navigate to my test.js and start it manually with node test.js, it runs normally. What am I doing wrong? I suspect I'm not handling the JSON packages properly (or my approach with starting my app from server.js is flawed). Any help is greatly appreciated! Thank you for your time.
Ok, I found the solution to this: https://github.com/ryanj/nodejs-custom-version-openshift/issues/2

heroku running gulp build

i am trying to install a node app onto heroku. My application requires both gulp build and gulp install to be called on the server upon instillation, however i am having troubles doing this.
I have tried writing this inside of the package.json:
"scripts":"gulp build && gulp install"
which works at first, but after about an hour the server must restart and recall the script causing for the contents of the server to be rebuilt. this removes all of my content such as newly written blogs or changes.
I have also tried using the heroku toolbelt
heroku run gulp build
heroku run gulp install
However, even though it produces the correct console write lines and looks asif it has made the necessary changes, it hasn't, the server produces an error which proves that the resources haven't been built meaning that the console command didnt make any changes to the actual server files.
Am i missing something out here? Thanks in advance.
So i have figured out that the problem lies with the fact that i have tried to use a LevelDB database on heroku. Apparently, heroku uses no-writable dynos, meaning that the levelDB database is unable to save.

Resources