npm install fails when package-lock.json is present - json

I have some strange issue regarding the package-lock.json.
We are using npm 5.6 and node 8.9.2.
We have some project with dependencies. The developers can install the deps and push the package-lock.json as recommended:
...
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha1-dHIq8y6WFOnCh6jQu95IteLxomM=",
"dev": true
}
}
...
They are getting their dependencies from https://registry.npmjs.org/..
Now we have some jenkins which gets its dependencies from some artifactory which serves as 'proxy' to https://registry.npmjs.org.
The build fails 75% of the times on some error like:
npm ERR! Unexpected end of JSON input while parsing near '...nalInternal" : {
Even when I clean the cache before with sudo npm clean cache --force (or remove .npm)
The error occurs always on a different place.
Now when I remove the package-lock.json before starting the build it works well every time.
A new package-lock.json is generated. It contains not the registry urls but the artifactory urls (https://artifactory/xxx). I thought it could maybe have to do with it. so I replaced the current package-lock.json in git with the one from jenkins. I tried again but again the same error and issue, only deleting the package-lock.json seems to solve it but as I read it's not recommended to ignore this file.
What could be an issue?

Related

npm start not working for react while install react script (react script : 3.4.0 version)

I am new to React js, While using npm start after install the react not working,I tried every process but no use. Thanks in advance
Error
cricdost#0.1.0 start C:\xampp\htdocs\cd-web
react-scripts start
There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.
The react-scripts package provided by Create React App requires a dependency:
"webpack": "4.41.2"
Don't try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:
C:\xampp\htdocs\node_modules\webpack (version: 4.39.2)
Manually installing incompatible versions is known to cause hard-to-debug issues.
If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.
To fix the dependency tree, try following the steps below in the exact order:
Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
Delete node_modules in your project folder.
Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder.
Run npm install or yarn, depending on the package manager you use.
In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:
If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
This may help because npm has known issues with package hoisting which may get resolved in future versions.
Check if C:\xampp\htdocs\node_modules\webpack is outside your project directory.
For example, you might have accidentally installed something in your home folder.
Try running npm ls webpack in your project folder.
This will tell you which other package (apart from the expected react-scripts) installed webpack.
If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.
P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cricdost#0.1.0 start: react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cricdost#0.1.0 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! C:\Users\XSC-10261\AppData\Roaming\npm-cache_logs\2020-02-20T04_56_31_650Z-debug.log
I had faced the same error. The solution that I found is to do the step-6 as described in Error message. That is to delete "webpack" folder of node_module folder under your root projects directory. For example
Assume that you installed "npm install create-react-app" in D:\Projects folder.
And then you ran "npx create-react-app firstproject" in D:\Projects folder. So, your actual react project folder is "D:\Projects\firstproject".
So, what I want to tell is don't delete "webpack" folder in "D:\Projects\firstproject\node_module" directory. Instead, delete "webpack" folder in "D:\Projects\node_module" directory.
And then, you can run "npm start" command in your actual react project directory "D:\Projects\firstproject".
I hope, this will work for you.

npm install not creating the json file

I updated npm installed node express,even though it is not creating the jason file. can any one please let me know how to fix this.
ramesh#ramesh-PC MINGW32 ~
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.
See npm help json for definitive documentation on these fields
and exactly what they do.
Use npm install <pkg> --save afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (ramesh)
ramesh#ramesh-PC MINGW32 ~
First initialize your project. Assuming your project lives in directory "sample" then:
cd sample
npm init // This will ask a bunch of questions. you can mostly just hit "enter". it will create the package.json file for you
npm i express --save
using npm init you can create package.json
To clarify a bit on the previous answers, npm install <package-name> and npm install <package-name> --save may fail if you try to run them from a directory that does not have an npm package.json file.
You might type something like npm install crud --save and get some confusing output like this:
npm install crud
npm WARN saveError ENOENT: no such file or directory, open '/Users/youruser/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/Users/youruser/package.json'
npm WARN youruser No description
npm WARN youruser No repository field.
npm WARN youruser No README data
npm WARN youruser No license field.
+ crud#0.0.28
That's not a very helpful error message -- the level is only "warn", and that last line makes it appear that the requested package got installed somewhere. But if you look in your directory, you will see it remains empty. The explanation of this "riddle" is that some package installers (like PHP's composer) will initialize a project and download the package, others (like Python's pip or npm) do not, so you have to initialize the directory and install packages separately.
Run npm init and answer some basic questions about your project, or copy a viable package.json file that follows the format below:
{
"name": "my-great-node-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
}
}
Be careful with the package name! The name cannot match the name of a package you trying to install.
Once the directory has been initialize, you should be able to run your npm install <package-name> --save command and have the package installed into the node_modules directory and have your package.json file updated.
Try not to make any space between words in your project folder name. For instance, instead of "My Portfolio" write it like "MyPortfolio". This worked for me and created json file automatically in my project folder.

Heroku does not read node version

I have a Node project that I want to host on Heroku. I have explicitly defined node and npm versions in my package.json (located in the root directory), which looks like this:
{
"name": "*********",
"version": "0.0.0",
"private": true,
"engines": {
"node": "0.12.x",
"npm": "2.5.x"
},
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "^1.13.3",
...
}
However, when I try to push the app to heroku
git push heroku master
Heroku tries to build the app, but it seems like it's not able to read the node and npm versions. Here is the response I get.
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version (latest stable) via semver.io...
remote: Downloading and installing node 4.2.1...
remote: Using default npm version: 2.14.7
Why does heroku not read the node and npm version from package.json?
#rdegges was right that the package.json wasn't correctly committed to Heroku. So just following the Heroku instructions didn't work for me for some reason. Here is what I had to do in order to make it work.
git clone <my git project>
heroku create <app name>
#remove package.json
mv package.json tmp_package.json
git add package.json
git commit -m "removed package.json"
#re-add package.json
mv tmp_package.json package.json
git add package.json
git commit -m "re-added package.json"
git push heroku master
This works for me -- make sure you've actually committed these changes to Git, and pushed the repository to Heroku. You may also want to specify exact Node and NPM release numbers for your Heroku app.
While this WILL WORK with the variable releases you've got specified, it's not recommended, as small changes in releases might cause issues for you.
For reference, here are the Heroku docs on specifying a Node.js runtime as well: https://devcenter.heroku.com/articles/nodejs-support#node-js-runtimes
I added the version to the package.json as others mentioned and it worked for me. These versions were referenced from the defaults that Heroku uses during the build if none are specified:
"engines": {
"node": "14.18.3",
"npm": "6.14.15"
},
Also, I'd recommend adding this setting to your app via the CLI for more output, which really helps:
heroku config:set NPM_CONFIG_LOGLEVEL=verbose --app=<your_app_name>
👍🏼
In an easy way
1- check your node version, let say it is like this: "node": "17.3.0"
2- Go inside the the package.json, at the very top below name and version add this
"engines": {
"node": "17.3.0",}
3- Delete package-lock.json then reinstall it by npm install.
After 3 hours working this mechanism helped me, I wanted to share with you all :) I hope it works for you too
Maybe your master branch is not the branch is not updated, try merging the branch that you want to deploy into master in order to use:
git push heroku master
Don't give 'x' on the version
"node": "0.12.x",
"npm": "2.5.x"
write complete version.
Ex.
"node": "0.12.0",
"npm": "2.5.0"
I tried the other solutions, but it didn't work for me. However, by changing the name field in package.json, it worked:
From:
{
...
"name": "foo"
...
}
To:
{
...
"name": "bar"
...
}
Alternative 2:
When I had to do the same on my other computer, it didn't work, but I tried removing package.json, recreating it from scratch, and then it worked for some odd reason (file metadata?):
$ rm package.json
$ npm init
Make sure the lockfile is up to date
In order to update the package-lock.json, run npm install and check in the changes to the file to git.
Then, git add . && git commit -m "update pkg-lock" && git push heroku master
I added the node version to package.json, but it would only accept it in the format
<major version>.x
i.e.
"name": "myapp",
"version": "1.0.0",
"engine": {
"node": "16.x"
}
I got that info from the heroku docs here - no other way of specifying it worked except that 16.x.
In my case the issue was with package.json, it was missed up due to some manual changes, so reverting to old version of repo solved my issue.

devDependencies ignored in npm?

I am the author of two npm modules, both with devDependencies.
The first one is simpleDbLayer. Install it:
npm install simpledblayer
The downloaded package.js file has devDependencies matching what is in the git repository:
//...
"devDependencies": {
"simpleschema": "0.3.x"
},
//...
Unfortunately, nodeunit test.js will fail because simpleschema wasn't installed (as it should have been). From the manual:
By default, npm install will install all modules listed as dependencies. With the --production flag, npm will not install modules listed in devDependencies
Even weirder (and this is the really strange issue I am most affected by) is my other module, simpledblayer-mongo:
npm install simpledblayer-mongo
In he installed package.js file, I have:
"devDependencies": {},
Which doesn't match what was actually published, which contains:
"devDependencies": {
"simpleschema": "0.3.x",
"simpleschema-mongo": "0.3.x"
},
Needless to say simpleschema and simpleschema-mongo is not installed.
Am I missing something?
Yes, by default it will install the devDependencies but only for your project (devDependencies in your package.json), not for modules in the npm repository.
If you want the devDependencies of your dependencies, force it by passing --dev to the npm command:
npm install simpledblayer --dev
Also, when you have the environment variable NODE_ENV set to production, it won't install the devDependencies either (not even the ones in your package.json).

Azure Website Instance not running defined Node Version in Package.json

Currently in Azure I am utilizing a 'Azure Website' instance to try and run Docpad (NodeJS App). Within my package.json file I have the following defined..
"engines": {
"node": "0.10.21",
"npm": "1.x"
},
I have tried numerous different entries, from 0.10.x to 0.8.x all listed here => http://azure.microsoft.com/en-us/documentation/articles/nodejs-specify-node-version-azure-apps/
The problem is that Docpad is using Dependencies with Semver Entries and Azure seems to be ignoring my defined Node version entirely, as there are errors such as...
npm WARN engine docpad#6.69.2: wanted: {"node":">=0.8","npm":">=1.2"} (current: {"node":"0.6.20","npm":"1.1.37"})
Because of this, I am getting critical/failure errors when NPM goes to install Docpad due to dependencies such as this...
npm ERR! Error: No compatible version found: rimraf#'^2.2.8'
npm ERR! Valid install targets:
npm ERR! ["1.0.0","1.0.1","1.0.2","1.0.4","1.0.5","1.0.6","1.0.7","1.0.8","1.0.9","2.0.0","2.0.1","2.0.2","2.0.3","2.1.0","2.1.1","2.1.2","2.1.3","2.1.4","2.2.0","2.2.1","2.2.2","2.2.3","2.2.4","2.2.5","2.2.6","2.2.8"]
I have even gone as far as to try printing the Node Version in my deployment script, only to have it return the Environment Variable Azure supposedly honors, but it is clearly invalid.
All I am trying to do is deploy a Docpad website on Azure and I am dumbfounded as to how this is so difficult to to just use a semi-recent version of node in Azure. Any help at all would be greatly appreciated!
node and npm are now npm packages that can be installed as dependencies of your project, so it will run with the correct versions once its dependencies are installed.
However, to install those packages you will need to start with newer versions than the ones you have in your engines section:
Without npm >= 3 installing the node package will break your system by removing the existing version of node too soon
Without node >= 4 the npm package won't work (it isn't specific as to what goes wrong)