webpack-encore: Installation guide does not work - yarn: Command "encore" not found
Followed the guideline for installing Encore on Symfony 4 as described here: https://symfony.com/doc/current/frontend/encore/installation.html
It consists of two steps:
composer require webpack-encore
yarn install
Requiring webpack-encore works fine. When I run yarn install, it does not install anything:
yarn install v1.9.4
warning package.json: No license field
warning No license field
[1/4] Resolving packages...
success Already up-to-date.
When I try to make a first build of encore, without changing anything, using
yarn encore dev
it gives me the following error:
yarn run v1.9.4
warning package.json: No license field
error Command "encore" not found.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 15
- Comments: 17 (1 by maintainers)
I just spent some time on this as well š So I created a new project and this is what you get, copy/paste in package.json run
yarn install
and thenyarn encore dev
should work!Maybe this could/should be pointed out in the tutorial, itās not really an obvious issue for those new to Symfony/Encore. Itās not a given thing that the very first thing you install with yarn is Encore and then youāre stuck.
This is my install order for a fresh project:
Since Iāve installed bootstrap, jquery and popper before Encore, I do have a package.json, yes.
Edit: It does indeed work if I install Encore before I install anything else with yarn. Once Iāve installed something with yarn, like bootstrap, it no longer works. Is there a workaround/fix for this, so I can add Encore to my existing project, or would I need to reinstall everything from scratch?
Edit2: About the workaround: Iāve copied the relevant parts from the new created projectās package.json to my existing project and called yarn install. Looks like it installed something. Gave me some warnings though:
Iāll see if it works anyway. š
When you require
webpack-encore
the recipe tries to copy this defaultpackage.json
file. As you can see it contains the depencies missing in your case and some useful npm/yarn scripts.The catch is⦠that copy doesnāt happen if a file already exists (to avoid overwriting userās files).
It should work fine if you add bootstrap/jquery/popper.js after calling
composer require webpack-encore
.package.json
doesnāt get indeed updated with the āscriptsā section which is needed to run the commands from the tutorial. You can try to add them manually to avoid creating a new project and installing all again.Well, the problem I had was because yarn install and yarn add was removing the @symfony files in node_modules.
Make sure your NODE_ENV environment variable exists and is set to ādevelopmentā, yarn install --production=false will do the trick as well, otherwise if you add any other packages it may end up removing them (the bastard).
This is why the command will not be found, at least in my case.