npm install error - invalid package.json - json

I'm using this tutorial to understand implementing oauth2 in Node.js.
This is my package.json:
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "coffee -w server.coffee"
},
"dependencies": {
"express": "3.3.4",
"jade": "*",
"coffee-script": "latest",
"passport-http": "latest",
"passport-http-bearer": "latest",
"passport-oauth2-client-password": "latest",
"oauth2orize": "latest",
"debug" "~0.7.2"
}
}
I'm getting the error:
npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected string
npm ERR! File: /Users/jashua/Desktop/auth/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/jashua/Desktop/auth
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.5
npm ERR! file /Users/jashua/Desktop/auth/package.json
npm ERR! code EJSONPARSE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/me/Desktop/auth/npm-debug.log
npm ERR! not ok code 0
Any ideas what's wrong with my package.json?

The error means exactly what it states, the JSON in your package.json is not valid and can't be parsed properly. Change "debug" "~0.7.2" to "debug": "~0.7.2".

Use this command to fix package.json related issue.
npm cache clean

C:\Program Files\nodejs>npm cache verify
Fixes it on Windows 10, run it with an Administrator command prompt Window.

I arrived at this page due to the same npm error, but a different cause. After viewing the log files, I realized that npm did not like my comment on the top line of the file.
// package.json
{ ...
}
After removing all comments, npm ran through everything beautifully. My comment was not necessary, so I'm fine as it is. But if you require comments within your xml, see How do I add comments to package.json for npm install?

I had the same issue caused by changes that I had made to my package.json file. I just reverted to my backup version of the package.json file. I attached that below if anyone else needs one:
{"name": "OpenShift-Sample-App",
"version": "1.0.0",
"description": "OpenShift Sample Application",
"keywords": [
"OpenShift",
"Node.js",
"application",
"openshift"
],
"author": {
"name": "OpenShift",
"email": "ramr#example.org",
"url": "http://www.openshift.com/"
},
"homepage": "http://www.openshift.com/",
"repository": {
"type": "git",
"url": "https://github.com/openshift/origin-server"
},
"engines": {
"node": ">= 0.6.0",
"npm": ">= 1.0.0"
},
"dependencies": {
"express": "~3.4.4"
},
"devDependencies": {},
"bundleDependencies": [],
"private": true,
"main": "server.js"
}

Sometimes you might have some weird unicode chars in your package.json. For example you might have \u00A0 (unicode non-breaking space) instead of a space somewhere. It looks the same in editor, so beware.
(I just had such problem after copying a small piece of config from a blog.)

My project was in D:\wwwroot\Projetos 2017\Android\PluginTest\PluginTest\plugins\cordova-plugin-iservice
The problem is space between Projetos(here)2017
I removed space to:
D:\wwwroot\Projetos2017\Android\PluginTest\PluginTest\plugins\cordova-plugin-iservice
and Work fine

Related

Failed to deploy Cloud Functions after upgrading to node 14

After bumping the node version on my Firebase project from node 10 to node 14 in my package.json, like so:
...
"engines": {
"node": "14"
},
...
Firebase throws an error whenever I try to deploy a function.
First, I run:
firebase deploy --only functions:foo
Afterwards, the console shows:
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> gts lint
version: 14
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> ttsc
✔ functions: Finished running predeploy script.
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (257.54 KB) for uploading
i pubsub: ensuring required API pubsub.googleapis.com is enabled...
i scheduler: ensuring required API cloudscheduler.googleapis.com is enabled...
✔ pubsub: required API pubsub.googleapis.com is enabled
✔ scheduler: required API cloudscheduler.googleapis.com is enabled
✔ functions: functions folder uploaded successfully
i functions: updating Node.js 14 function foo(us-central1)...
✔ functions[foo(us-central1)]: Successful upsert schedule operation.
Functions deploy had errors with the following functions:
foo(us-central1)
To try redeploying those functions, run:
firebase deploy --only "functions:foo"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Unfortunately, there's not much logs that I can get from the error:
By running:
firebase deploy --only functions:foo
I get the following error logs:
{"code":3,"message":"Build failed: > sharp#0.28.3 install /workspace/node_modules/sharp\n> (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)\n\nsharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.6/libvips-8.10.6-linux-x64.tar.br\n\n> protobufjs#6.10.2 postinstall /workspace/node_modules/protobufjs\n> node scripts/postinstall\n\n\n> functions#undefined prepare /workspace\n> npm run compile\n\n\n> functions# compile /workspace\n> ttsc\n\nsh: 1: ttsc: not found\nnpm ERR! code ELIFECYCLE\nnpm ERR! syscall spawn\nnpm ERR! file sh\nnpm ERR! errno ENOENT\nnpm ERR! functions# compile: ttsc\nnpm ERR! spawn ENOENT\nnpm ERR! \nnpm ERR! Failed at the functions# compile script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /builder/home/.npm/_cacache/_logs/2021-06-06T04_27_25_637Z-debug.log\nnpm ERR! code ELIFECYCLE\nnpm ERR! errno 1\nnpm ERR! functions#undefined prepare: npm run compile\nnpm ERR! Exit status 1\nnpm ERR! \nnpm ERR! Failed at the functions#undefined prepare script.\nnpm ERR! This is probably not a problem with npm. There is likely additional logging output above.\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR! /builder/home/.npm/_logs/2021-06-06T04_27_25_673Z-debug.log; Error ID: beaf8772"}
In addition, my node version is:
node --version
v14.17.0
After looking at the Cloud Build from the Google Cloud Console, I've noticed that the following error:
2021-06-07T03:28:00.714478581ZStep #4 - "builder": src/cloud_functions/userInfo/https/onCall/uploadAvatar.ts(4,19): error TS7016: Could not find a declaration file for module 'sharp'. '/workspace/node_modules/sharp/lib/index.js' implicitly has an 'any' type.
To fix this, I simply added the following code in the tsconfig.json:
{
"compilerOptions": {
"noImplicitAny": false,
...
},
...
}

How to pass the JSON validation of write-manifest.json when adding "debugLocale"?

I'm trying to build my first localised SPFX WebPart for Sharepoint Online. I've added an additional language de-de.js in the loc folder and now I'm trying to change the write-manifest.json to use my new language on debug by adding the `"debugLocale" property to it:
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->",
"debugLocale": "de-de"
}
Checking the official instructions of Microsoft and inspecting the JSON sheme of the write-manifest.json shows this should compile, but when I gulp serve it returns:
Build target: DEBUG
./node_modules/#microsoft/node-core-library/lib/JsonSchema.js:178
throw new Error(prefix + os.EOL +
^
Error: JSON validation failed:
./config/write-manifests.json
Error: #/ (Defines configuration options for the...)
Additional properties not allowed: debugLocale
at validateObjectWithCallback (./node_modules/#microsoft/node-core-library/lib/JsonSchema.js:178:19)
at JsonSchema.validateObjectWithCallback (./node_modules/#microsoft/node-core-library/lib/JsonSchema.js:193:13)
at JsonSchema.validateObject (./node_modules/#microsoft/node-core-library/lib/JsonSchema.js:175:14)
at WriteManifestsTask._readConfigFile (./node_modules/#microsoft/gulp-core-build/lib/tasks/GulpTask.js:311:28)
at WriteManifestsTask.onRegister (./node_modules/#microsoft/gulp-core-build/lib/tasks/GulpTask.js:87:32)
at Object.initialize (./node_modules/#microsoft/gulp-core-build/lib/index.js:299:24)
at SPWebBuildRig.initialize (./node_modules/#microsoft/sp-build-common/lib/BuildRig.js:61:19)
at SPWebBuildRig.initialize (./node_modules/#microsoft/sp-build-common/lib/SPBuildRig.js:29:15)
at SPWebBuildRig.initialize (./node_modules/#microsoft/sp-build-web/lib/SPWebBuildRig.js:15:15)
at Object.exports.initialize (./node_modules/#microsoft/sp-build-web/lib/index.js:23:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello-world#0.0.1 start: `gulp serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello-world#0.0.1 start script.
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! ~/.npm/_logs/2019-01-09T16_43_53_070Z-debug.log
How can I solve this issue?
Between 1.5 and 1.6, the build tasks appeared to have changed. I have confirmed the issue with 1.6+.
If you modify your write-manfiest.json "debugLocale" to "buildSingleLocale", everything will work as expected. I think the docs and the schema may be out of date.
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->",
"buildSingleLocale": "de-de"
}
I just tried that and it works in my setup.
Created webpart using yo #microsoft/sharepoint with default options (using React as Javascript framework)
Added de-de.js file to loc folder and changed values so I can see that is really grabs the correct file
Added "debugLocale": "de-de" to write-manifests.json
Run gulp serve
Texts used are from de-de.js
My versions:
yo - 2.0.3
#microsoft/sharepoint generator - 1.4.1 (I know it is old one)
npm - 5.6.0 (Yes, also old one)
But, once I update the #microsoft/sharepoint generator to latest version 1.7.1 it stopped working. It seems that the issue occurs since version 1.6.0
Workaround is to run it with --locale parameter like gulp serve --locale=de-de or to use older version:
npm uninstall #microsoft/generator-sharepoint -g
npm install #microsoft/generator-sharepoint#1.5.1 -g

Unable to run npm install successfully due to unmet peer dependencies

I have package.json file in which following devDependencies are mentioned:
"devDependencies": {
"bower": "^1.7.7",
"connect-ssi": "^1.1.0",
"grunt": "~0.4.5",
"grunt-contrib-compass": "^1.1.0",
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-handlebars": "^0.11.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-qunit": "~0.5.2",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-jsdoc": "^1.1.0",
"karma": "^0.13.22",
"karma-jasmine": "^0.3.7"
}
Now when I run npm install it gives me following errors:
UNMET PEER DEPENDENCY jasmine-core#*
npm WARN EPEERINVALID karma-jasmine#0.3.8 requires a peer of jasmine-core#* but none was installed.
npm WARN EPACKAGEJSON hirebuddy-prototype#0.0.1 No repository field.
hirebuddy-prototype is the name in the package.json.
Will running npm install install all the dependencies mentioned in the package.json or do I need to install jasmine-core and karma-jasmine separately?
This is a weakness in karma-jasmine. In its package.json, jasmine-core is listed as a peerDependency, and NPM 3 no longer installs these automatically. So you have to add jasmine-core in your own package.json. So just npm install jasmine-core --save-dev, and cross your fingers that the latest version is compatible. It should be.
Info: http://blog.npmjs.org/post/110924823920/npm-weekly-5

Package.json syntax error?

I'm trying to run npm install and I get this:
root#WF-DEV1:/var/www/laravel# npm install
npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected token }
npm ERR! File: /var/www/laravel/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
This is my package.json file:
{
"name": "bootstrap-tagsinput",
"title": "Bootstrap Tags Input",
"version": "0.5.0",
"description": "jQuery plugin providing a Twitter Bootstrap user interface for managing tags.",
"scripts": {
"test": "karma start --single-run --no-auto-watch"
},
"main" : "dist/bootstrap-tagsinput.js",
"repository": {
"type": "git",
"url": "git://github.com/timschlechter/bootstrap-tagsinput.git"
},
"author": "Tim Schlechter",
"contributors": [{
"name": "Luckner Jr Jean-Baptiste"
}],
"license": "MIT",
"homepage": "http://timschlechter.github.io/bootstrap-tagsinput/examples/",
"download": "http://timschlechter.github.io/bootstrap-tagsinput/build/bootstrap-tagsinput.zip",
"keywords": [
"tags",
"bootstrap",
"input",
"select",
"form"
],
"readmeFilename": "README.md",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-cli": "~0.1.13",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-jquerymanifest": "~0.1.4",
"grunt-zip": "~0.15.0",
"karma": "~0.12.19",
"phantomjs": "~1.9.7-15",
"karma-phantomjs-launcher": "~0.1.3",
"karma-jasmine": "~0.1.5",
"grunt-karma": "~0.8.3",
"bower": "~1.3.8",
"grunt-bower-task": "~0.4.0"
},
"banner": "/*\n * <%= pkg.name %> v<%= pkg.version %> by <%= pkg.author %>\n * <%= pkg.license.url %>\n */\n"
}
Any help would be appreciated!
The JSON appears to be valid (I ran it through an online parser). I ran the same package.json under windows and got the following output:
D:\workspace\deleteme>npm install
npm ERR! install Couldn't read dependencies
npm ERR! Windows_NT 10.0.10240
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! node v4.1.1
npm ERR! npm v2.14.4
npm ERR! file D:\workspace\deleteme\package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected token '<' at 1:1
npm ERR! <!DOCTYPE html>
npm ERR! ^
npm ERR! File: D:\workspace\deleteme\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! Please include the following file with any support request:
npm ERR! D:\workspace\deleteme\npm-debug.log
The npm-debug.log started with:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install' ]
2 info using npm#2.14.4
3 info using node#v4.1.1
4 verbose readDependencies loading dependencies from D:\workspace\deleteme\package.json
5 error install Couldn't read dependencies
6 verbose stack Error: Failed to parse json
6 verbose stack Unexpected token '<' at 1:1
6 verbose stack <!DOCTYPE html>
6 verbose stack ^
6 verbose stack at parseError (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:379:11)
6 verbose stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:68:23)
6 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:48:5
6 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:76:16
6 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
7 verbose cwd D:\workspace\deleteme
So on a hunch, I changed your devDependencies to dependencies and that worked. So I don't have a firm answer, but it seems there is definitely something in your file that npm has a problem with - it's just not a JSON error.
For some reason, the wrong code was in my package.json. Not sure how it got there but I definitely didn't put it there. I reinstalled everything and it's now fixed and the right code is in there now.

NPM does not publish dependencies

I have been fooling around with Node and npm Packages as CLI applications. I have a project with a package.json, all filled in correctly. When I run the application with different arguments via WebStorm, it all works fine. If I publish the npm package however... there are no dependencies... the npm site can't find one.. and when I install the CLI application, it fails running because yeah... the dependencies aren't pulled in...
This is my package.json
{
"name": "wmg",
"version": "0.0.8",
"description": "A Commandline Foolin around",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/Arvraepe/wmg.git"
},
"keywords": ["Stuff", "Foolin"],
"target": "main",
"preferGlobal": true,
"bin": {
"wmg": "wmg.js"
},
"author": "Arne Van Raepenbusch <arvraepe#gmail.com>",
"license": "ISC",
"devDependencies": {
"prompt": "^0.2.14",
"restify": "^3.0.3",
"underscore": "^1.8.3"
}
}
I tried running pakmanager deps, but that gave me this strange error
======================= WARNING =======================
Assuming browser mode by default is deprecated.
Include browserDependencies in your package.json
-- OR --
pakmanager -e browser build
In the next release of pakmanager, the node environment will be assumed as default
=======================================================
Targeted Environment: browser
[[[deps]]]
[ERROR] The following packages are `require`d, but not in the package, nor on npm:
wmg
pakmanager {}
======================= WARNING =======================
Assuming browser mode by default is deprecated.
Include browserDependencies in your package.json
-- OR --
pakmanager -e browser build
In the next release of pakmanager, the node environment will be assumed as default
=======================================================
Surely my package isn't supposed to be dependent on itself?
Can someone shed some more light on this?
I looked at your package, and as others have noted you have devDependencies listed but no dependencies. Typically devDependencies is for things like test frameworks, which you need to work on the package but not to use it. Both prompt and restify are used in your app and should be listed in a dependencies object instead of devDependencies.
Your package.json file contains no dependencies. Only devDependencies which npm assumes are required only for development (mocha for example) and are not required for installation.
If any of your devDependencies are actual user dependencies move them to dependencies.