I am trying to use a Composer package from a private Mercurial repository on bitbucket. Composer says it can't find the package.
Let's call the package my-user/my-private-repo. For what it's worth, I've added my SSH public key to bitbucket for this repository. The composer.json file for the package looks like this:
{
"name": "my-user/my-private-repo",
"version": "0.0.1",
"description": "Some Composer Package",
"author": "me",
"license": "blah",
"require-dev": {
"phpunit/phpunit": "5.0.*"
}
}
And the composer.json for the project in which I want to use that package looks like:
{
"require": {
"my-user/my-private-repo": "^0.0.1"
},
"repositories": [
{
"type":"package",
"package":{
"name":"my-user/my-private-repo",
"version": "default",
"source":{
"type": "hg",
"url": "bitbucket.org/my-user/my-private-repo",
"reference":"default"
}
}
}
]
}
When I run composer update, I get the following error:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package my-user/my-private-repo could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
I've read everything I can find on SO that seems relevant, but I can't seem to get past this error. How can I use my Composer package in a project?
Don't use the "package" type. This is only really useful for software that is NOT inside a repository. It is meant as a replacement to integrate ZIP downloads into Composer.
Additionally, it is complicated to collect all necessary info for that "package" type.
Repositories are way easier:
"repositories": [
{
"type": "vcs",
"url": "ssh://hg#bitbucket.org/my-user/my-private-repo"
}
]
The repository must have a valid composer.json file - and it really helps if it also has tagged versions, because dependencies using branches will break eventually because you cannot signal backward incompatible changes and cannot go back to a defined earlier version.
The composer.json MUST NOT have a version. That's what repository tags are for.
Note: The "type":"vcs" works generally well and will detect Git, Hg, or SVN repos.
Related
When I try deploying my Firebase cloud functions I get the following error.
Desired behavior: Deploy functions successfully.
Error:
Error: There was an error reading functions/package.json:
functions/lib/index.js does not exist, can't deploy
Cloud Functions
Full log:
name#name-MacBook-Pro functions % firebase deploy
=== Deploying to 'newtiktok-21570'...
i deploying functions Running command: npm --prefix "$RESOURCE_DIR"
run lint
functions# lint /Users/name/Desktop/Yoveo/functions
eslint "src/**/*"
/Users/name/Desktop/Yoveo/functions/src/index.ts
186:67 warning 'timestamp' is defined but never used
#typescript-eslint/no-unused-vars 377:86 warning 'mediaNum' is
defined but never used #typescript-eslint/no-unused-vars 377:104
warning 'commentText' is defined but never used
#typescript-eslint/no-unused-vars 377:125 warning 'commentID' is
defined but never used #typescript-eslint/no-unused-vars 419:119
warning 'commentID' is defined but never used
#typescript-eslint/no-unused-vars 463:121 warning 'commentID' is
defined but never used #typescript-eslint/no-unused-vars 520:75
warning 'mediaNum' is defined but never used
#typescript-eslint/no-unused-vars 732:25 warning 'slap' is
defined but never used #typescript-eslint/no-unused-vars
✖ 8 problems (0 errors, 8 warnings)
Running command: npm --prefix "$RESOURCE_DIR" run build ✔ functions:
Finished running predeploy script.
Error: There was an error reading functions/package.json:
My p.json:
{
"name": "functions",
"scripts": {
"lint": "eslint \"src/**/*\"",
"build": "",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "12"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0"
},
"devDependencies": {
"#typescript-eslint/eslint-plugin": "^4.8.1",
"#typescript-eslint/parser": "^4.8.1",
"eslint": "^7.14.0",
"eslint-plugin-import": "^2.22.0",
"firebase-functions-test": "^0.2.0",
"typescript": "^3.8.0"
},
"private": true
}
cd into your functions folder and run this command
npm run-script build
This will create the lib/index.js file that is missing
firebase uses main field in package.json as program entry point,
set it properly, probably like this.
"main": "lib/src/index.js",
For some reason recently the build flow of firebase functions changed.
It used to be:
npm --prefix ./functions install ./functions
firebase deploy --only functions
now it is:
npm --prefix ./functions install ./functions
npm --prefix ./functions run build
firebase deploy --only functions
I have not researched what caused this change, but adding this as build step fixed the problem for me.
functions/lib/index.js does not exist
In case you are working in firebase project that contains a frontend or is structured as a monorepo, this error may also stem from having accidentally imported a frontend file in the functions backend part of the project. For all files that are not within your functions project scope, the typescript compiler will refuse to compile ts files referencing them. So in this case, the solution is to search for any imports containing /src/ (or any other paths pointing outside) and remove (or correct) them within your functions project.
you just have to change the main inside package.json file from lib/index.js to your index file which is usually under the src folder
Solved:
I was able to solve the problem by removing everything associated with Firebase functions. And running: firebase init again. After I cd functions run npm install. Then I was able to deploy successfully after fixing an error with:
3:26 error 'express' should be listed in the project's dependencies. Run 'npm i -S express' to add it import/no-extraneous-dependencies
Changing the firebase.json file to the following fixed my issue:
{
"functions": {
"predeploy": ["npm --prefix ./functions run build"],
"source": "functions"
}
}
I was able to fix this same issue by following Felix K indications, answered on Apr 28, 2021.
In case you are working in firebase project that contains a frontend or is structured as a monorepo, this error may also stem from having accidentally imported a frontend file in the functions backend part of the project. For all files that are not within your functions project scope, the typescript compiler will refuse to compile ts files referencing them. So in this case, the solution is to search for any imports containing /src/ (or any other paths pointing outside) and remove (or correct) them within your functions project.
In my case, I've accidently imported an interface from the frontend. When updating this import I was able to successfully deploy my function.
Solution from Edward Amoah Idun:
cd into your functions folder and run this command
npm run-script build
This will create the lib/index.js file that is missing
Yes, but it will create the index.js file that is missing in the wrong folder. Still necessary to check that you don't have imports from another projects.
The lib folder is for your built functions code, so you haven't built it. This can be done automatically by adding redeploy code to your firebase.json config file:
{
"functions": [
{
"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run build"],
// rest of config...
}
]
}
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.
In a project I inherited, the packages.json looks roughly like this:
{
"name": "...",
"version": "...",
"description": "",
"author": "...",
"license": "ISC",
"dependencies": {
"lodash": "^3.10.1",
"assemble": "^0.4.37",
"cheerio": "^0.16.0",
"grunt": "^0.4.4",
"grunt-build-control": "^0.1.3",
},
"keywords": [
"handlebars-helper-md",
"handlebars-helper-rel"
]
}
When I first got it, lodash was ~2.4.1 and I'm trying to update it to 3.10.1 (as shown above). However, npm continues to install 2.4.1 at the top-level (Despite the package.json requesting the newer version) and it does not install the requested versions 2.4.1 or 2.4.2 in some of the dependencies (like assemble and cheerio). Thus when I npm install lodash#3.10.1 it complains about unmet dependencies.
I've tried removing node_modules and npm clear cache and rm -rf $HOME/.npm in different orders and combinations with no change.
How do I get lodash#3.10.1 to install at the top-level and the requested version of lodash in all the dependencies (and not have the dependencies use the top-level copy of lodash -- which I thought was the normal way for npm to work)?
Preferably a solution would not require updating all the dependencies to new versions (assuming that is even possible). That could be a solution, but that would require a lot more validation to make sure nothing broke.
I am trying to install this plug in which is the Angular UI Bootstrap, I do not need the full library, only that plug in, and I am getting the error:
the command I am entering in the terminal:
bower install bower-bootstrap-accordion --save
and then the error:
Bower error: ENOTFOUND Package bower-bootstrap-accordion not found
here is the bower.json
{
"name": "bower-bootstrap-accordion",
"license": "MIT",
"version": "0.11.0",
"author": {
"name": "https://github.com/angular-ui/bootstrap/graphs/contributors"
},
"dependencies": {
"bower-bootstrap-collapse": "0.11.0"
},
"main": "ui-accordion-tpls.js"
}
Link to the plugin
do I have to install the full library ?
bower-bootstrap-accordion is not registered in the Bower registry and therefore the Bower client cannot find it by name.
You can use the Git repository URL when defining the dependency. This will save the Bower client the need to search for the package URL in the Bower registry.
"dependencies": {
"bower-bootstrap-accordion" : "git://github.com/ui-bootstrap-bower-test/bower-bootstrap-accordion.git"
}
In addition this package has dependencies on additional packages such as bower-bootstrap-collapse, bower-bootstrap-transition which are also not registered in the Bower registry. You will have to include it in the same way in your dependencies.
I think all those packages are from the same author - https://github.com/ui-bootstrap-bower-test/
Using the $ bower init command, I have created a bower.json for my package and registered it with Bower, no problem.
After looking at the Github homepages for some popular Bower packages, e.g. RequireJS and Modernizr, I've noticed their repo's don't contain a bower.json or a component.json. How is this possible?
I've also noticed that when I download any Bower package, the package contains a .bower.json file (note the dot in the beginning) and that file contains quite a bit more information than what I was asked during $ bower init for my package. For example, below is the .bower.json from Modernizr:
{
"name": "modernizr",
"homepage": "https://github.com/Modernizr/Modernizr",
"version": "2.6.2",
"_release": "2.6.2",
"_resolution": {
"type": "version",
"tag": "v2.6.2",
"commit": "ca45d02757b83367d8455d477e3cbc42dfdee035"
},
"_source": "git://github.com/Modernizr/Modernizr.git",
"_target": "~2.6.2",
"_direct": true
}
When I download my newly created package, it just contains the same info that I originally checked in to git.
Is there a new format for bower.json that I should be using? Or did I simply miss something in the setup process?
Bower doesn't need a bower.json or a component.json to install packages. The manifest file provide some useful info, like dependencies, ignored files, version and etc, but in the end it just downloads Git commits and place them somewhere.
In the case of Modernizr/Require.js, someone just registered their repos and Bower is retrieving a tag.
About the .bower.json file: this is generated by Bower itself after installing a package. It contains some more verbose info about a package, like the commit from which the package was retrieved, for example.
TL;DR: Keep using bower init, it'll do the right thing for you!
I am using Yeoman and the following is the content of my bower.json file. I thought it might help you. (I have installed all the latest versions of bower and grunt)
{
"name": "yowebapp",
"version": "0.0.0",
"dependencies": {
"sass-bootstrap": "~3.0",
"requirejs": "~2.1.4",
"modernizr": "~2.6.2",
"jquery": "~1.9.1",
"d3":"~3.3.2",
"angular":"1.0.7"
},
"devDependencies": {}
}
and I download my dependencies with bower install.