3
votes

I work in a Symfony 4.2 project, and try to use Bootstrap theming (so I need to compile Sass code). I followed the process given in the official doc, which indicates to use webpack-encore. But I have an error when using it accordingly to the doc.

Here is the page indicating the process : https://symfony.com/doc/current/frontend/encore/simple-example.html

So I installed Encore, and then I launch yarn run encore. And here is what it says in the terminal :

yarn run v1.16.0
warning package.json: No license field
error Command "encore" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

So I visited the site indicated in the error, which says :

You may define scripts in your package.json file.

And if I look in my package.json in the root directory, it indeed only says :

  "devDependencies": {
    "bootstrap": "^4.3.1",
    "jquery": "^3.4.1",
    "node-sass": "^4.12.0",
    "popper": "^1.0.1",
    "sass-loader": "^7.0.1"
  }
}

There is no script for any encore command :-(

However the rest seems good. Here is an extract of composer.json :

...
    "require": {
...
        "symfony/webpack-encore-bundle": "^1.5",
...
    },
...

And I have a webpack.config.js .

I runned composer require encore and yarn install without any error.

But nowhere in the Symfony doc I found anything about tweaking the package.json oO So how do I make it work ? Why doesn't the yarn run encore work ?

1
Damn, I forgot a step : 'yarn init' - Julien Busset

1 Answers

0
votes

I have the same problem, in symfony 5 project with webpack-encore.

sh: encore: not found

You have to install webpack-encore.

yarn add @symfony/webpack-encore --dev
yarn run encore dev

or with npm.

npm install @symfony/webpack-encore --dev

If encore can't find a directory, file, package or error in webpack.config.js, you will get.

npm ERR! command sh -c encore dev

for example this error.

Running webpack ...

 ERROR  Failed to compile with 1 errors          4:34:57 PM

This dependency was not found:

* assets/scss/material-kit-react.scss?v=1.4.0 in ./assets/index.jsx

To install it, you can run: npm install --save assets/scss/material-kit-react.scss?v=1.4.0 Entrypoint react [big] = runtime.js vendors~react.js react.js 
npm ERR! code 2 
npm ERR! path /path/www 
npm ERR! command failed 
npm ERR! command sh -c encore dev

npm ERR! A complete log of this run can be found in: 
npm ERR!     /root/.npm/_logs/2021-01-21T16_34_57_638Z-debug.log

Here Encore can't find assets/scss/material-kit-react.scss?v=1.4.0 in de assets directory