【问题标题】:Command "encore" not found when trying yarn encore dev command尝试使用 yarn encore dev 命令时找不到命令“encore”
【发布时间】:2021-07-30 13:45:22
【问题描述】:

我目前卡在 Encore/Webpack 安装上。我按照symfony.com 的步骤进行操作。但是当继续the simple example 时,我被困在运行yarn encore dev 上。我收到错误消息:“找不到命令“encore””。在安装 Encore 并导航到视图后运行 symfony server:start 时也出现错误:

An exception has been thrown during the rendering of a template ("Could not find the entrypoints file from Webpack: the file "path/entrypoints.json" does not exist.").

据我所知,entrypoints.json 应该是自动生成的。我有 Yarn 1.22.10 和 NodeJS 14.16.1。

我做了什么

我执行了命令composer require symfony/webpack-encore-bundle 和yarn install

  1. 我查看了 StackOveflow 问题'error Command "encore" not found.' when running 'yarn run encore' in Symfony4、webpack encore dev-server not found /、Error Command "encore" not found. (separate backend webpack)、Can't run encore dev
  2. 我执行了命令composer require webpack
  3. 我注意到我的 package.json 没有一个脚本对象,命令 encore dev 应该是存在的。我观看了一段 YouTube 视频并关注了它 (https://youtu.be/Fs_4FMoSO90)。这就是为什么我知道这一点。我想知道为什么我没有它。下面是视频中的 package.json。我的 package.json 只有 dev 依赖 Bootstrap。
  4. 已执行npm install

视频中的Package.json:

{
  "devDependencies": {
    "@symfony/webpack-encore": "^0.31.0",
    "core-js": "^3.0.0",
    "regenerator-runtime": "^0.13.2",
    "webpack-notifier": "^1.6.0"
  },
  "license": "UNLICENSED",
  "private": true,
  "scripts": {
    "dev-server": "encore dev-server",
    "dev": "encore dev",
    "watch": "encore dev --watch",
    "build": "encore production --progress"
  }
}

我的 package.json:

{
  "devDependencies": {
    "bootstrap": "^5.0.0"
  }
}

我删除了 package.json、package-lock.json 并再次执行 yarn install 并安装了一些包。我不需要 NPM。我已经从我的 Yarn.lock 中获得了 Bootstrap(这是唯一的东西)。我仍然有两个错误。

在 Yivi 的建议下,我执行了 composer req webpack、yarn install 和 yarn encore dev。不同之处在于我执行了composer require symfony/webpack-encore-bundle,这是symfony网站安装页面上提到的。 yarn encore dev 命令现在尝试运行 webpack,但出现以下错误:Error: Encore.enableStimulusBridge is not a recognized property or method. webpack.config.js:26 Object.<anonymous>

webpack.config.js 第 26 行

    // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
    .enableStimulusBridge('./assets/controllers.json')

【问题讨论】:

  • 其他东西必须被打破,或者你必须错过一些步骤,尽管你相信你没有。我刚刚试过composer create-project symfony/website-skeleton test-encore、cd test-encore、composer req webpack、yarn install 和yarn encore dev 效果很好。
  • 我更新了我的问题。我有 NodeJS 版本 14.16.1。我不小心给了我的 NPM 版本。
  • 我执行了composer req webpack、yarn install 和yarn encore dev。不同之处在于我执行了composer require symfony/webpack-encore-bundle,这是symfony网站安装页面上提到的。 yarn encore dev 命令现在尝试运行 webpack,但出现以下错误:Error: Encore.enableStimulusBridge is not a recognized property or method. webpack.config.js:26 Object.<anonymous>。
  • 刺激支持是added in 0.32。您可以发布 your 文件的相关部分吗?您也可以尝试reinstalling the recipes 并修改您的版本。
  • 升级刺激和再来一次确实有帮助:symfony.com/blog/…

标签: symfony yarnpkg package.json webpack-encore


【解决方案1】:

你的建议奏效了。我用composer recipes:install symfony/webpack-encore-bundle --force -v 安装了食谱,现在yarn encore dev 成功编译了webpack。我现在也知道我不小心在我的项目中保留了视频中的 package.json,这解释了为什么我的错误从 Command encore not found 变为 Error: Encore.enableStimulusBridge is not a recognized property or method. webpack.config.js:26 Object.<anonymous>

【讨论】:

    猜你喜欢
    • 2021-10-27
    • 1970-01-01
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 2021-06-12
    • 2021-12-25
    • 1970-01-01
    相关资源
    最近更新 更多