node.js app azure deployment from bitbucket - node.js

I am getting following error when i try to deploy nodejs app from bitbucket.
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling node.js deployment.
KuduSync.NET from: 'D:\home\site\repository' to: 'D:\home\site\wwwroot'
undefined:38
}
^
An error has occurred during web site deployment.
SyntaxError: Unexpected token } in JSON at position 1090
at Object.parse (native)
at Object.<anonymous> (D:\Program Files (x86)\SiteExtensions\Kudu\63.60712.2926\bin\Scripts\selectNodeVersion.js:179:44)
at Module._compile (module.js:570:32)
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.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
undefined:38\r\n}\r\n^\r\n\r\nSyntaxError: Unexpected token } in JSON at position 1090\r\n at Object.parse (native)\r\n at Object.<anonymous> (D:\Program Files (x86)\SiteExtensions\Kudu\63.60712.2926\bin\Scripts\selectNodeVersion.js:179:44)\r\n at Module._compile (module.js:570:32)\r\n at Object.Module._extensions..js (module.js:579:10)\r\n at Module.load (module.js:487:32)\r\n at tryModuleLoad (module.js:446:12)\r\n at Function.Module._load (module.js:438:3)\r\n at Module.runMain (module.js:604:10)\r\n at run (bootstrap_node.js:394:7)\r\n at startup (bootstrap_node.js:149:9)\r\nD:\Program Files (x86)\SiteExtensions\Kudu\63.60712.2926\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
Using node 6.9.1
package.json
{
"name": "example",
"version": "1.0.0",
"description": "REST APIs for example",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+abc"
},
"author": "abc",
"license": "ISC",
"homepage": "abc#readme",
"dependencies": {
"azure-storage": "^2.1.0",
"body-parser": "^1.17.1",
"change-case": "^3.0.1",
"dateformat": "^2.0.0",
"dotenv": "^4.0.0",
"express": "^4.15.2",
"jsonwebtoken": "^7.3.0",
"minimist": "^1.2.0",
"morgan": "^1.8.1",
"mssql": "^4.0.1",
"multer": "^1.3.0",
"nconf": "^0.8.4",
"node-friendly-response": "^3.1.4",
"request": "^2.81.0",
"require-dir": "^0.3.1",
"swagger-node-express": "^2.1.3",
"tedious": "^2.0.0",
"tedious-promises": "^0.4.1",
"underscore": "^1.8.3",
"winston": "^2.3.1"
}
}
Is it because of the node modules which i have used?
Or is it the problem during the loading of modules?

It seems that your package.json is not a valid JSON.
Update:
Kudu uses the following code to read the package.json file, see line 179 of selectNodeVersion.js.
json = existsSync(packageJson) && JSON.parse(fs.readFileSync(packageJson, 'utf8'));
So, before you push the package.json to github, you can use the code below to verify the file on your local:
var fs = require("fs");
var json = JSON.parse(fs.readFileSync("./package.json", 'utf8'));
console.log(json);
For example, I added one more } at line 38 in package.json your provided above, I would get the same error as yours:
Or you can just use the command npm install to check it:

Related

Issues with ES6 import/ from syntax

i have created an app which i am running it on my windows pc and works fine. is a MERN application now i have seted up a machine with ubuntu so i can serve it. but i cant run the back end i have the following error:
import mongoose from "mongoose"; ^^^^^^^^ SyntaxError: Unexpected identifier at Module._compile (internal/modules/cjs/loader.js:723:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) 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:623:3)`
all node modules are installed,
node installed 10.19.0,
npm installed,
mongo db installed,
nodemodules installed,
"type":"module" is on json file:
{
"name": "myidea",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"serve": "npx nodemon index.js",
"seed": "node db/seeds.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^5.1.0",
"body-parser": "^1.20.1",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"gridfs-stream": "^1.1.1",
"jsonwebtoken": "^8.5.1",
"method-override": "^3.0.0",
"mongoose": "^6.6.5",
"mongoose-unique-validator": "^3.1.0",
"multer-gridfs-storage": "^5.0.2"
},
"type": "module"
}
But still when i do npm run serve or npm run seed i have the error above. what em i missing here?
i have tried npm run serve and npm run seed and still i am getting the same error despite the fact ii have added the "type":"module" on the json

NodeJS - TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received undefined (mkdirp module nodejs)

I have a Node/Angular project that won't run because of this error. I am getting the following error:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
More context for that error:
PS C:\Users\Vinay\retail-billpay-node> node server
internal/validators.js:124
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:124:11)
at resolve (path.js:139:9)
at pathArg (C:\Users\Vinay\retail-billpay-node\node_modules\mkdirp\lib\path-arg.js:15:10)
at mkdirp (C:\Users\Vinay\retail-billpay-node\node_modules\mkdirp\index.js:10:10)
at Object.<anonymous> (C:\Users\Vinay\retail-billpay-node\app\helpers\winston.js:26:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (C:\Users\Vinay\retail-billpay-node\app\services\LogService.js:9:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
code: 'ERR_INVALID_ARG_TYPE'
}
And here is my package.json if it helps:
{
"name": "retail-billpay-node",
"version": "1.0.0",
"description": "start your node express app from this boilerplate code",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "siddhant-np",
"license": "ISC",
"dependencies": {
"async": "2.6.1",
"bluebird": "3.5.3",
"body-parser": "1.18.3",
"crypto": "1.0.1",
"csvtojson": "2.0.8",
"dotenv": "6.0.0",
"express": "4.16.3",
"extract-zip": "1.6.7",
"imap-simple": "4.3.0",
"ioredis": "4.6.2",
"kafka-node": "^5.0.0",
"lodash": "4.17.10",
"md5": "2.2.1",
"mkdirp": "0.5.1",
"moment": "2.22.2",
"moment-timezone": "0.5.21",
"mongoose": "5.2.9",
"nodemailer": "5.1.1",
"otp.js": "1.1.0",
"request": "2.87.0",
"util": "0.11.1",
"winston": "3.0.0",
"winston-daily-rotate-file": "3.2.1",
"xlsx": "0.14.1",
"xml-parse": "0.3.1",
"xml2js": "0.4.19",
"xmlbuilder": "10.0.0"
}
}
OK, I figured out the issue. I thought the error was telling me that path was undefined. When it fact it was saying the variables passed into path.join() were undefined. And that was because I forgot to add my .env file to the root so it could grab those variables.
Since it was an enterprise project so they don't keep .env file in the source code, I asked them and put it root.

Error : Cannot find Module 'cors' in fabric 1.2

I was getting Error: Cannot find module 'fabric-client'error then manually I ran 'npm install fabric-client#1.0.5' inside node_module then I am getting below error
[root#ip-172-31-61-27 controller]# node app.js module.js:538
throw err;
^
Error: Cannot find module 'cors'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/ec2-user/AWSNodeApp/controller/app.js:27:11)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
We already have an entry of 'cors' in the package.json file but still it given above error.
Below is the package.json file :-
{
"name": "awsnodeapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.538.0",
"body-parser": "^1.17.1",
"cors": "^2.8.3",
"express": "^4.15.2",
"express-session": "^1.15.2",
"fabric-ca-client": "1.3.0",
"fabric-client": "1.3.0",
"fs-extra": "^2.0.0",
"log4js": "^3.0.6",
"uuid": "^3.3.2",
"ws": "^6.1.0"
}
}
Since your app.js requires cors module, you need to install and add to package.json.
npm install cors --save
You can find the answer from this old post: Error: Cannot find module 'cors'

How do you get express to work on Heroku app?

I have a app on Heroku and when I run node server.js it's throwing a error and saying Error: Cannot find module 'express'.
I've cleared the npm cache, rebuilt the app, checked the package.json & dependencies. Nothing much is working for me and I'm just looking for solutions now.
throw err;
^
Error: Cannot find module 'express'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/app/server.js:1:79)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
Trying to get the app to start.
Here's the package.json
{
"name": "SCOGEAgent",
"version": "0.0.0",
"description": "A simple Blockstack app",
"main": "index",
"scripts": {
"browserify": "browserify requires.js -o public/bundle.js",
"start": "run browserify & node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/blockstack/hello-blockstack.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/blockstack/hello-blockstack/issues"
},
"homepage": "https://github.com/blockstack/hello-blockstack#readme",
"devDependencies": {
"browserify": "^14.1.0",
"express": "^4.16.4",
"opn": "^4.0.2"
},
"dependencies": {
"browserify": "^14.1.0",
"express": "^4.16.4",
"opn": "^4.0.2",
"#types/node": "^11.13.0",
"blockstack": "^18.0.4",
"express-ws": "^4.0.0",
"json-pointer": "^0.6.0",
"react-router-dom": "^5.0.0",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
"websocket-stream": "^5.5.0"
}
}
Express should be in your dependencies not devDependencies. Here's how you know where to put your third-party dependencies.
Does the app need the dependency to run? Put it in dependencies
Does the app need the dependency to build, test, lint, or any other
task for development? Put it in devDependencies.
The only time this gets fuzzy is when you need to build the project before you run it. Then some of your build dependencies might be placed in dependencies instead of devDependencies. I'm sure there is a more professional way to manage this but that's how I do it.

Error: Cannot find module 'lodash/keys' - Heroku Node environment

I keep getting this error when deploying my Node and Mean app to Heroku. The app seems to work normally when I run it locally but does not like it when I push it to Heroku.
module.js:471
throw err;
^
Error: Cannot find module 'lodash/keys'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/app/node_modules/mongoose/node_modules/async/internal/iterator.js:16:13)
at Module._compile (module.js:570:32)
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)
This is my package.json file
{
"name": "utdknow",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.6.12",
"body-parser": "^1.14.1",
"crypto-js": "^3.1.8",
"ejs": "^2.3.4",
"express": "^4.13.3",
"lodash": "^4.17.3",
"lodash.keys": "^4.2.0",
"moment": "^2.17.0",
"mongoose": "^4.2.5",
"ng-file-upload": "^12.0.4"
}
}
It seems like modules are not correctly installed. Try cleaning cache and deploy your app to re-install all dependencies:
https://github.com/heroku/heroku-repo
heroku plugins:install heroku-repo
heroku repo:purge_cache --app appname

Resources