I'm trying to build a repository/package for my personal ESLint config files. I have all of my configuration files built the way I would like, and now I am trying to install this package to test it.
In this scenario, I have two packages:
#me/eslint-config is the package containing my ESLint config files.
test-package is the package on/in which I am trying to install #me/eslint-config.
When I try to install the #me/eslint-config package, peer dependencies are not installed, nor are they even mentioned during the installation.
Both packages currently only reside locally on my machine, side-by-side, in the same directory:
<parent_dir>:
- eslint-config
- package.json
- ...
- test-package
- package.json
- ...
The package.json file for #me/eslint-config looks as follows:
{
...
"dependencies": {
"#typescript-eslint/parser": "5.29.0"
},
"peerDependencies": {
"eslint": "8.18.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "39.3.3",
"eslint-plugin-prefer-arrow": "1.2.3",
"#typescript-eslint/eslint-plugin": "5.29.0"
}
...
}
I am installing this package in test-package as follows:
$> cd /path/to/test-package
$> npm i ../eslint-config --save-dev
NPM properly installs all other dependencies, including the #me/eslint-config package itself, but does not install the peerDependencies of #me/eslint-config.
This is using NPM v8.1.0.
This article seems to suggest that NPM >7 installs peer dependencies automatically. This is obviously not working for me.
Things I have already tried that have not fixed the problem:
Deleting node_modules/ and package-lock.json from test-package and reinstalling everything.
Pinning all peerDependencies versions in #me/eslint-config.
Adding all peerDependencies in #me/eslint-config as both dependencies and peerDependencies in #me/eslint-config.
tl;dr NPM isn't installing peerDependencies
I had the same error on former version of npm and as you mention, npm ^8 now install peer dependencies.
But here could be ways of fining your problem
1 : estlint is a devDependencies (A guess)
eslint should be devDependencies and not a peerDependencies.
Maybe npm doesn't accept you to install it then.
I search a bit but couldn't find any real thread discussing about this
That said, I wouldn't install it as dependencies since it will be pushed to your production build, what, I think, you do not want.
2 : Being up to date
Try it with the latest version of npm
download the latest version of npm : npm install -g npm#latest
Delet node_modules/ and package-lock.json from test-package and reinstall everything. as you did already
2 : allowJs
If eslint is an js package & you see it being installed in the node_modules folder.
Inside the tsconfig.json file, under the compilerOptions add allowJs: true and set strict: false
"compilerOptions": {
"allowJs": true,
"strict": false,
Close all your instance of vs-code
Restart & retry (No need to remove the package-lock or so)
Related
I upgraded one of my packages by using npm i #pulumi/akamai#latest, and I see the updated devDependency in my project's package.json, with the code below.
"devDependencies": {
"#pulumi/akamai": "^1.0.0",
.....other dependencies
}
However my yarn.lock file is unchanged, with
"#pulumi/akamai#^0.1.0":
version "0.1.0"
resolved "https://registry.yarnpkg.com/#pulumi/akamai/-/akamai-0.1.0.tgz#e6eed04448670719fd4fbc3df06023c0b61b780b"
integrity sha512-Zs44yZrULrBMEA3ezb/A4baVX3cNQlE2+yrBBR75SfkK1TmhqitarEWnM1/JOQ/z7EIJZJN8SdqE5hsvXf/ssA==
dependencies:
"#pulumi/pulumi" "^2.0.0
I've tried running yarn, yarn install, and yarn add #pulumi/akamai#latest, but none of these commands are updating my yarn.lock. How can I update the yarn.lock file?
I have created my own npm feed in Azure Artifacts. I can publish my package and use it in my applications.
In my applications, the package is referenced like this in the package.json
`"#op/breeze-helpers": "^0.1.5"`
If I now publish version 0.1.6 of my package, delete my package from node_modules and run npm i , npm installs version 0.1.5 again !
I even tried npm i --cache c:/tmp/empty-cache to make sure it was not getting the package from cache, but it ends up the same. npm keeps installing version 0.1.5
what am doing wrong, I thought with the caret, the next minor should be downloaded when running npm i ?
The package-lock.json sets your currently installed version of each package in stone, and npm will use those exact versions when running npm install.
So it will download the package versions from the package-lock.json file.
I want to be on latest version always.
You could try to set the "*" as the dependency package version.
For example:
"dependencies": {
"#types/bootstrap": "*",
"#types/jquery": "*",
"bootstrap": "*"
}
Then it will always download the latest version of the target packages.
I want to update a dependency (packageX) without changing a locked dependency of that package, (packageY). In my package-lock.json, I have:
"packageX": {
"requires": {
"packageY": "1.0.0",
}
},
Each time I do "npm install packageX," I'd like to update packageX but have packageY stay on the defined version. How can I do that?
There is no way to do this, may be this link can explain better https://dev.to/saurabhdaware/but-what-the-hell-is-package-lock-json-b04
The story about package.json vs package-lock.json is tricky: npm install does not ignore package.json versions, nor does it ignore the package-lock.json. What it does is verify that the package.json and package-lock.json correspond to each other. That is, if the semver versions described in package.json fit with the locked versions in package-lock.json, npm install will use the latter completely, just like npm ci would.
Now, if you change package.json such that the versions in package-lock.json are no longer valid, your npm install will be treated as if you'd done npm install some-pkg#x.y.z, where x.y.z is the new version in the package.json for some-package.
In my package.json file I have:
"dependencies": {
"#aws/dynamodb-data-mapper": "^0.7.3",
"#aws/dynamodb-data-mapper-annotations": "^0.7.3",
"#my-company/common": "file:../common",
...
}
#my-company/common specifies a local module which is installed by yarn.
However, when I run npm prune, this module is pruned.
I thought that including it in the package.json dependencies object would stop it from being pruned? Did I miss something?
For those who come across this, I discovered that running npm ls showed that there was an error with the common module.
Installing with NPM instead of Yarn fixed the issue.
Installing with Yarn did create the package within node_modules, however there was obviously an error somewhere which I couldn't uncover.
I have my own NPM package in bitbucket as private repository which I installed in my main project as following:
"devDependencies": {
"my-package": "git+ssh://git#bitbucket.org/{name}/my-package.git"
}
This works like a charm, but there's a problem with the package itself. It contains a package.json with its own dependencies, but my main NPM is not installing this, it does not seem to keep in consideration what my package's package.json contains.
E.g: I am now missing packages that my own packages requires.
What can I do to make NPM always install my package packages defined in package.json?
Structure wise:
MyApp
- package.json (I run npm install on this one)
- some other php files..
- node_modules
- my-package
- package.json <-- This contains dependencies, which are not installed
Solved it, problem was that we defined our packages in the devDependencies, which should be in the dependencies.