For my Laravel course, I need to install npm.
To install npm, I had to go to nodejs.org, installed it. Then in cmd, I write npm install
and then I got this error-
npm WARN saveError ENOENT: no such file or directory, open 'C:\xampp\htdocs\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\xampp\htdocs\package.json'
npm WARN htdocs No description
npm WARN htdocs No repository field.
npm WARN htdocs No README data
npm WARN htdocs No license field.
What to do with this?
npm install is used to install the required modules that will be used in your application.
It uses the package.json file to know which modules need to be installed and run.
In you case it seems there is no package.json file created. So you have to create a package.json file first, using the command npm init.
Go into your main directory and run the preceding command, follow the steps like enter the application name, ...etc. and the file will be created.
Then use the npm install command to install any module you wish to, and the package.json will be updated and will keep track of the modules installed in your application.
Related
I have a project with the composer.lock file.
I installed packages with the command:
composer install
Now I would like to rollback that composer install command to the state as it was before running it.
How to remove all packages without affecting composer.lock file?
Is there any single composer command to do that?
I tried:
composer remove *
but I got:
[UnexpectedValueException]
"LICENSE" is not a valid alias.
I tried:
composer remove */*
But then I get bunch of print like:
bin/console is not required in your composer.json and has not been removed
Package "bin/console" listed for update is not locked.
Why composer remove * did not work at all? AFAIK the package name as VendorName/PackageName is a common convention for Packagist but not a must (if you use private repos) so how one would be able to remove all packages named IdontHaveAnySlash etc. at once?
I may use someting similar to:
for package in $(composer show | awk '{print $1}'); do composer remove --no-interaction --dev --no-install "$package"; done
But that is not a simple and single composer command.
Also composer often complains about a package being a part (dependency) of another one so composer does not uninstall it.
Removal failed, doctrine/annotations is still present, it may be required by another package. See composer why doctrine/annotations.
As my intention is to rollback to the state that did not have any package installed but only files: composer.lock and potentially composer.json I really don't care about any dependencies, packages versions, downloading repositories' urls etc.
I just want to have a project without any installed dependencies as it was before.
Is there any single composer command to do that?
My:
composer --version
is:
version 2.2.7 2022-02-25 11:12:27
Following yivi answer I created a simple test to verify:
mkdir -p /tmp/composer-install
cd /tmp/composer-install
curl -o composer.json https://raw.githubusercontent.com/composer/composer/18246212db7103d0a2688febcc336f77183275ee/composer.json
curl -o composer.lock https://raw.githubusercontent.com/composer/composer/d955458f271edb4fcc055a394f90a60a8328a2a8/composer.lock
sha1sum composer.json > composer.json.sha1
sha1sum composer.lock > composer.lock.sha1
composer install
sha1sum -c composer.json.sha1
sha1sum -c composer.lock.sha1
that outputs:
composer.json: OK
composer.lock: OK
So both composer.json and composer.lock are not affected by composer install so the only one thing to achieve the rollback (uninstall) of the composer install is to remove the vendor directory
rm -rf vendor
However as yivi mentioned:
If some other plugin (e.g Symfony Flex) makes changes to your existing files during the process, you'd better have the project on top of a version control system, in which case reverting is managed by VCS, not of composer.
I did not test against that case.
rm -rf vendor
In any case, install should not make any changes to a lockfile, so there shouldn't be anything to "revert" from an install but deleting the installed files.
If the lockfile does not originally exist, then it will be created.
If some other plugin (e.g Symfony Flex) makes changes to your existing files during the process, you'd better have the project on top of a version control system, in which case reverting is managed by VCS, not of composer.
As my intention is to rollback to the state that did not have any package installed but only files: composer.lock and potentially composer.json
For you to be able to run composer install at all, you need at the very least composer.json to exist. install reads from the lockfile (composer.lock), but requires the JSON configuration file to exist as well. If the lockfile does not exist, update will be run instead and the lockfile will be created.
I tried composer remove
remove is the opposite from require. It removes packages from composer.json, as require adds them. Not the opposite of install. There is no opposite of install, as it does not make much conceptual sense. If one needs to delete the installed project... one can always do so.
I did composer create-project laravel/laravel Push "8.0"
In blog file do.
composer require laravel/ui
php artisan ui bootstrap
php artisan ui vue --auth
Then change package.json file to :
https://github.com/laravel/laravel/blob/8.x/package.json#L12
Then do npm install --save-dev cross-env
npm install vue
Second do npm install&&npm run dev
chenasmartin#MacBook-Air-von-Chenas Push % npm install&&npm run dev
up to date, audited 788 packages in 736ms
81 packages are looking for funding
run npm fund for details
found 0 vulnerabilities
dev
npm run development
development
mix
✖ Mix
Compiled with some errors in 785.65ms
WARNING in ./resources/js/bootstrap.js 4:2-22
Module not found: Error: Can't resolve 'bootstrap' in '/Applications/XAMPP/xamppfiles/htdocs/Push/resources/js'
Did you mean './bootstrap'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories (node_modules).
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.
ERROR in ./resources/sass/app.scss
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Can't find stylesheet to import.
╷
8 │ #import '~bootstrap/scss/bootstrap';
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
resources/sass/app.scss 8:9 root stylesheet
at processResult (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/webpack/lib/NormalModule.js:751:19)
at /Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/webpack/lib/NormalModule.js:853:5
at /Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/loader-runner/lib/LoaderRunner.js:399:11
at /Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/loader-runner/lib/LoaderRunner.js:251:18
at context.callback (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/loader-runner/lib/LoaderRunner.js:124:13)
at /Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass-loader/dist/index.js:54:7
at Function.call$2 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:98905:16)
at render_closure1.call$2 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:84431:12)
at _RootZone.runBinary$3$3 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:29484:18)
at _FutureListener.handleError$1 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:28006:21)
at _Future__propagateToListeners_handleError.call$0 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:28313:49)
at Object._Future__propagateToListeners (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:3896:77)
at _Future._completeError$2 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:28159:9)
at _AsyncAwaitCompleter.completeError$2 (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:27807:12)
at Object._asyncRethrow (/Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:3699:17)
at /Applications/XAMPP/xamppfiles/htdocs/Push/node_modules/sass/sass.dart.js:19760:20
1 ERROR in child compilations (Use 'stats.children: true' resp. '--stats-children' for more details)
webpack compiled with 2 errors and 1 warning
How can i fix that
Try to install bootstrap manually with npm so you run the following command:
npm install bootstrap
If this not work, you can manually switch back to node-sass,
Run the following command to install the node-sass dependencies:
npm install node-sass
Now change the following code :
mix.sass('resources/sass/app.sass', 'public/css', {
implementation: require('node-sass')
});
Delete your node_modules folder and retry to run :
npm install
I new in Composer. I have been searching and I have managed to install it:
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
If I understand the second line makes it accessible globally in my computer.
I have checked that have installed correctly as I have written composer in the terminal and it gives me a list of commands and descriptions.
Now I want to install Stripe. I follow that instructions: https://stripe.com/docs/recipes/subscription-signup#creating-the-signup-form-using-checkout
I write in the terminal: composer require stripe/stripe-php
I see they install a folder in the root of the computer (in a Mac, the house with my name) the folder: vendor/stripe
Now the Stripe instructions have a file with:
require_once('vendor/autoload.php'); If I am in MAMP how should I reach to the Stripe files with the require? How should be the link?
In your project (inside MAMP) you should run composer install. There you will see the vendor file appear and will be easier for you to track the path.
As you correctly mentioned you will require the autoload.php file which is in inside the vendor file which will appear.
Just make sure that before run the composer install that you are inside your project folder.
i am new to mac os.i have installed laravel in mamp server using manually not using composer.also installed composer but i dont know how to run commands like php artisan and all.
in windows i can easily point to composer like as i given answer to this question
Where and how can I run composer commands?
please help me how to in mamp server ?
thank you in advance
Updated::
Usage:
command [options] [arguments]
Options:
--help (-h) Display this help message
--quiet (-q) Do not output any message
--verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
--version (-V) Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
--no-interaction (-n) Do not ask any interactive question
--profile Display timing and memory usage information
--working-dir (-d) If specified, use the given directory as working directory.
Available commands:
about Short information about Composer
archive Create an archive of this composer package
browse Opens the package's repository URL or homepage in your browser.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Set config options
create-project Create new project from a package into given directory.
depends Shows which packages depend on the given package
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader
dumpautoload Dumps the autoloader
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
home Opens the package's repository URL or homepage in your browser.
info Show information about packages
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses Show information about licenses of dependencies
list Lists commands
remove Removes a package from the require or require-dev
require Adds required packages to your composer.json and installs them
run-script Run the scripts defined in composer.json.
search Search for packages
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Show information about packages
status Show a list of locally modified packages
suggests Show package suggestions
update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json and composer.lock
CPU664:~ narendrab$ php artisan
Could not open input file: artisan
CPU664:~ narendrab$
In mac os, you can easily install composer globally by
curl -sS https://getcomposer.org/installer | /Applications/MAMP/bin/php5/bin/php
mv composer.phar /usr/local/bin/composer
Then you can just use command composer everywhere without specifying full path. You have to use full path for MAMP php since php comes with mac will be default.
Edit: run artisan command within the project directory.
This is weird, seems like something small that I'm missing. A few days ago, when I composer install I get Vendor directories with their own .git, this allows me to make changes and update my own packaged repositories.
Today, after running composer install, the .git directories inside each package folder is missing! (I think this might have something to do with installing from cache?)
Could someone please try re-create this?
$ git clone https://github.com/nathankot/rbhpi
$ cd rbhpi
$ ./composer.phar install
$ cd vendor/rbhpi/core
$ ls -a
From the above commands, the .git directory is missing for me.
I couldn't find this spec in the docs, but I did find it in this faq item:
Remove the .git directory of every dependency after the installation
Any solutions to my problem?
Composer prefers the dist package of your dependencies, meaning dowloading a .tgz from github and unpacking it. If you want the source, install your vendors with
composer install --prefer-source
This will do a git checkout like you want.