Expressjs App on Vercel, not installing peer dependencies - node.js

I'm building a small expressjs app that I host on vercel. Testing the app locally works fine, but when deploying and running on vercel, the require stack fails on my serverless function.
This is what vercel tells me :
2023-02-03T14:41:20.325Z undefined ERROR Cannot find module 'ndarray-pixels'
Require stack:
- /var/task/node_modules/#gltf-transform/functions/dist/functions.js
- /var/task/_index.js
My package.json looks like this
{
"name": "test - app",
"version": "1.0.0",
"description": "",
"main": "_index.js",
"scripts": {
"start": "node --experimental-fetch _index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"#gltf-transform/core": "^2.5.1",
"#gltf-transform/extensions": "^2.5.1",
"#gltf-transform/functions": "^2.5.1",
"cors": "^2.8.5",
"express": "^4.18.2",
"fetch": "^1.1.0",
"gl-matrix": "^3.4.3",
"ktx-parse": "^0.4.5",
"ndarray-pixels": "^1.0.0",
"node-fetch": "^2.6.9",
"three": "^0.148.0"
}
}
.
I've tried adding the build override on vercel, with no luck.
npm install --legacy-peer-deps
Any help or pointers are much appreciated

This problem can happen if you accidentally send the node_modules folder to the git remote repository. If it is the case, remove the node_modules folder, create a .gitignore file if it not exists and just write node_modules inside the gitignore file.
Now you can:
git rm -r --cached .
git add --all .
git commit -a -m "Versioning untracked files"
git push

Related

NPM CLI package.json invalid

Before posting the issue, I surfed on all possible websites to fix the issue with Node.js- npm cli I am encountering. None of the answers worked for me and I got stuck with. Can someone help to fix it?
The npm cli was running perfectly and it suddenly started to work giving me the traceback Please verify that the package.json has a valid 'main' entry. Even if I re-installed the node.js it has not resolved the issue. (see screenshot below)
The version node.js 16.17.1 on Windows 10
Screenshot:
The content of the package.json
{
"name": "npm-bundled",
"version": "1.1.2",
"description": "list things in node_modules that are bundledDependencies, or transitive dependencies thereof",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/npm-bundled.git"
},
"author": "Isaac Z. Schlueter <i#izs.me> (http://blog.izs.me/)",
"license": "ISC",
"devDependencies": {
"mkdirp": "^0.5.1",
"mutate-fs": "^1.1.0",
"rimraf": "^2.6.1",
"tap": "^12.0.1"
},
"scripts": {
"test": "tap test/*.js -J --100",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},
"files": [
"index.js"
],
"dependencies": {
"npm-normalize-package-bin": "^1.0.1"
}
}
Thanks in advance.
AKA
[Solved]:
Thanks everyone. The problem was lying in the directory C:\Users\your_comp_name\AppData\Local\node & C:\Users\your_comp_name\AppData\Roaming\npm that only needs to be removed to run npm cli further.

Build node.js app using yarn but getting error Command "build" not found

This is my package.json file.
{
"name": "moneymall",
"version": "1.0.0",
"description": "A money mall server app.",
"main": "index.js",
"author": "Anbu Selvan",
"license": "ISC",
"keywords": [],
"dependencies": {
"body-parser": "^1.18.3",
"cors": "^2.8.5",
"e": "0.0.4",
"express": "^4.16.4",
"mysql": "^2.16.0",
"pug": "^2.0.3",
"yarn": "^1.15.2"
},
"devDependencies": {
"nodemon": "^1.18.10",
"react-scripts": "^2.1.8"
}
}
Run yarn build and get this error.
yarn run v1.15.2 error Command "build" not found. info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this
command
You don't seem to have a script.build key defined in your package.json file. Sample entry for building with webpack library would be:
"scripts": {
"build": "webpack"
}
If you execute yarn run it will show the list of commands which can be run.
Ideally yarn run dev will do the trick of compiling the build
Please re-read the yarn documentation. You don't seem to have a script key declaring what you build script is, and thus Yarn does not know what to load.

How to get phantomjs to install on elastic beanstalk?

I have been google and reading different SO and github issues about this for the last few hours. I have tried adding a phantomjs config file to an .ebextensions folder, I have tried including a buildspec file that installs phantom js, and a bunch of other things and I cant seem to get phantomjs installed on my elastic beanstalk instance running nodejs. This is the package.json and the error. Any ideas as how to get this working would be really helpful. Thanks!
This is the package.json
{
"name": "webcrawler",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha **/*.test.js",
"test-watch": "nodemon --exec 'npm test'",
"start": "node app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"#types/cheerio": "^0.22.6",
"#types/phantom": "^3.2.3",
"cheerio": "^1.0.0-rc.2",
"express": "^4.16.2",
"line-by-line": "^0.1.6",
"node-schedule": "^1.2.5",
"phantom": "^4.0.12",
"phantomjs-prebuilt": "^2.1.16",
"request": "^2.83.0",
"write": "^1.0.3"
},
"devDependencies": {
"#types/chai": "^4.0.10",
"#types/express": "^4.11.0",
"chai": "^4.1.2",
"mocha": "^4.0.1",
"sinon": "^4.1.3"
}
}
error
phantomjs-prebuilt#2.1.16 install /tmp/deployment/application/node_modules/phantomjs-prebuilt
node install.js
PhantomJS not found on PATH Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 Verified
checksum of previously downloaded file Extracting tar contents (via
spawned process) Removing
/tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder
/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1515525280131/phantomjs-2.1.1-linux-x86_64
-> /tmp/deployment/application/node_modules/phantomjs-prebuilt/lib/phantom
Running npm install:
/opt/elasticbeanstalk/node-install/node-v7.10.1-linux-x64/bin/npm
Setting npm config jobs to 1 npm config jobs set to 1 Running npm
with --production flag Failed to run npm install. Snapshot logs for
more details. UTC 2018/01/09 19:17:20 cannot find application npm
debug log at /tmp/deployment/application/npm-debug.log
Traceback (most recent call last):
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 695, in ....
Not the most ideal solution, but I downgraded the elastic beanstalk instance to an earlier version an then it started to work.

#line/bot-sdk in azure not working

I create a web application in Azure.
And deploy from a repository in bitbucket.
but azure always give me this error
Error: Cannot find module '#line/bot-sdk'
package.json:
{
"name": "linebot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"#line/bot-sdk": "^2.0.0",
"body-parser": "^1.17.2",
"express": "^4.15.3",
"fs-extra": "^3.0.1"
},
"devDependencies": {},
"engines": {
"node": ">=6"
},
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC"
}
It looks like the "#line/bot-sdk" has not been installed properly. First, please make sure the package.josn is located in root folder of the Repository.
Once you push your code to bitbucket, Kudu will sync the repository to /site/wwwroot on Azure App Service and run npm install --production here by executing the deployment script.
:: 3. Install npm packages
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd !NPM_CMD! install --production
IF !ERRORLEVEL! NEQ 0 goto error
popd
)
Finally, you may want to check dependencies whether or not they have been installed via App Service Editor (https://[YouAppName].scm.azurewebsites.net/dev/wwwroot/).

Heroku - error running browserify on Node deployment

I'm trying to deploy a Node app to Heroku, but I'm having an issue successfully running browserify when the app is deployed.
When I'm running locally, I browserify my script with npm run bundle like so (from package.json):
"bundle": "./node_modules/browserify/bin/cmd.js build/main.js -o public/scripts/bundle.js
which browserifies the script in build/main.js and puts it into public/scripts/bundle.js.
For deploying to Heroku, I added
"postinstall": "npm run bundle"
However, when I deploy, I get the following error:
Error: ENOENT: no such file or directory, open 'public/scripts/bundle.js.tmp-browserify-59309133185877094263'
Well, that's correct, that file shouldn't exist... yet. When I run npm run bundle locally, I do see that file briefly pop into existence, but then it is quickly removed and I'm left with a nice updated bundle.js.
I read through Heroku's docs on this, but I'm miffed... can anyone clarify how to get through this?
For reference, here are the relevant parts of my package.json:
"scripts": {
"bundle": "./node_modules/browserify/bin/cmd.js build/main.js -o public/scripts/bundle.js",
"postinstall": "npm run bundle"
},
"dependencies": {
"body-parser": "^1.17.1",
"browserify": "^14.1.0",
"ejs": "^2.5.6",
"express": "^4.15.2",
"jquery": "^3.2.1",
"path": "^0.12.7",
"superagent": "^3.5.2"
},
"devDependencies": {},
"engines": {
"node": "6.8.1",
"npm": "4.0.5"
}
Solved! I had bundle.js included in my global gitinore configuration. Just had to take that out, good to go!

Resources