'错误命令'encore'未找到.'在 Symfony4 中运行“yarn run encore"时 [英] 'error Command "encore" not found.' when running 'yarn run encore' in Symfony4

查看:32
本文介绍了'错误命令'encore'未找到.'在 Symfony4 中运行“yarn run encore"时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个 Symfony 4.2 项目中工作,并尝试使用 Bootstrap 主题(所以我需要编译 Sass 代码).我遵循了官方文档中给出的过程,该过程表明使用 webpack-encore.但是根据文档使用它时出现错误.

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.

这是指示过程的页面:https://symfony.com/doc/current/frontend/encore/simple-example.html

所以我安装了 Encore,然后我启动了 yarn run encore.这是它在终端中所说的:

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 :

如果我在根目录中查看我的 package.json,它确实只说:

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"
  }
}

没有任何 encore 命令的脚本:-(

There is no script for any encore command :-(

不过其他的都还好.这是 composer.json 的摘录:

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

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

我有一个 webpack.config.js .

And I have a webpack.config.js .

我运行 composer require encoreyarn install 没有任何错误.

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

但是在 Symfony 文档中我没有找到任何关于调整 package.json oO 的内容 那么我该如何让它工作呢?为什么 yarn run encore 不起作用?

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 ?

推荐答案

我有同样的问题,在使用 webpack-encore 的 symfony 5 项目中.

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

sh: encore: not found

你必须安装 webpack-encore.

You have to install webpack-encore.

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

或使用 npm.

npm install @symfony/webpack-encore --dev

如果 encore 在 webpack.config.js 中找不到目录、文件、包或错误,你会得到.

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

例如这个错误.

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

这里Encore在de assets目录下找不到assets/scss/material-kit-react.scss?v=1.4.0

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

这篇关于'错误命令'encore'未找到.'在 Symfony4 中运行“yarn run encore"时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆