roots / acorn

Laravel components for WordPress plugins and themes
https://roots.io/acorn/
MIT License
815 stars 94 forks source link

[bug] php fatal error on Sage mergeDependencies() random using bud.js #308

Closed riccardomel closed 1 year ago

riccardomel commented 1 year ago

Agreement

Describe the issue

Hi,

The issue is caused in : bundle('app')->enqueue();

Seems that the app bundle generated by bud.js is null instead an array, but no error is present during the build of assets: │ app │ ◉ js/runtime.01bfc1.js ✔ 1.05 kB │ ◉ css/app.92df17.css ✔ 56.29 kB │ ◉ js/app.00f750.js ✔ 115.27 kB

The stange part is that sometimes works fine, sometimes the errors appear.

Expected Behavior

Build works, and no error is generated on: bundle('app')->enqueue();

Actual Behavior

[08-Sep-2023 08:24:35 UTC] PHP Fatal error: Uncaught TypeError: Roots\Acorn\Assets\Bundle::mergeDependencies(): Argument roots/bud#2 must be of type array, null given, called in /var/www/XXX.it/releases/8/wp-content/themes/wordpress-evolve-theme/vendor/roots/acorn/src/Roots/Acorn/Assets/Concerns/Enqueuable.php on line 65 and defined in /var/www/XXX.it/releases/8/wp-content/themes/wordpress-evolve-theme/vendor/roots/acorn/src/Roots/Acorn/Assets/Concerns/Enqueuable.php:199

Steps To Reproduce

On Sage theme folder:

  1. npm install
  2. npm run build
  3. Sometimes, this causes the error on sage.

version

latest, but is present also in the previous releases

Logs

[08-Sep-2023 08:24:35 UTC] PHP Fatal error:  Uncaught TypeError: Roots\Acorn\Assets\Bundle::mergeDependencies(): Argument roots/bud#2 must be of type array, null given, called in /var/www/XXX.it/releases/8/wp-content/themes/wordpress-evolve-theme/vendor/roots/acorn/src/Roots/Acorn/Assets/Concerns/Enqueuable.php on line 65 and defined in /var/www/XXX.it/releases/8/wp-content/themes/wordpress-evolve-theme/vendor/roots/acorn/src/Roots/Acorn/Assets/Concerns/Enqueuable.php:199

Configuration

/**
 * Build configuration
 *
 * @see {@link https://roots.io/docs/sage/ sage documentation}
 * @see {@link https://bud.js.org/guides/configure/ bud.js configuration guide}
 *
 * @typedef {import('@roots/bud').Bud} Bud
 * @param {Bud} app
 */

//import purgeCssWordPress from 'purgecss-with-wordpress';

export default async (app) => {
  /**
   * Application entrypoints
   * @see {@link https://bud.js.org/docs/bud.entry/}
   */
  app
    .entry({
      app: ['@scripts/app', '@styles/app'],
      editor: ['@scripts/editor', '@styles/editor'],
    }).minimize()

    /**
     * Directory contents to be included in the compilation
     * @see {@link https://bud.js.org/docs/bud.assets/}
     */
    .assets(['images'])

    /**
     * Matched files trigger a page reload when modified
     * @see {@link https://bud.js.org/docs/bud.watch/}
     */
    .watch(['resources/views', 'app'])

    /**
     * Proxy origin (`WP_HOME`)
     * @see {@link https://bud.js.org/docs/bud.proxy/}
     */
    .proxy('https://XXX.lndo.site')

    /**
     * Development origin
     * @see {@link https://bud.js.org/docs/bud.serve/}
     */
    .serve('http://0.0.0.0:3099')

    /**
     * URI of the `public` directory
     * @see {@link https://bud.js.org/docs/bud.setPublicPath/}
     */
    .setPublicPath('/wp-content/themes/wordpress-evolve-theme/public/')

    /*
    * Extensions
    * Purge
    * https://bud.js.org/extensions/bud-purgecss/
    * */
    /*.purgecss({
      content: [app.path(`resources/views/**`)],
      safelist: [...purgeCssWordPress.safelist],
    })*/

    /*
    * Critical
    * https://bud.js.org/extensions/bud-criticalcss
    * */

    /**
     * Generate WordPress `theme.json`
     *
     * @note This overwrites `theme.json` on every build.
     *
     * @see {@link https://bud.js.org/extensions/sage/theme.json/}
     * @see {@link https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/}
     */
    .wpjson.settings({
    color: {
      custom: false,
      customDuotone: false,
      customGradient: false,
      defaultDuotone: false,
      defaultGradients: false,
      defaultPalette: false,
      duotone: [],
    },
    custom: {
      spacing: {},
      typography: {
        'font-size': {},
        'line-height': {},
      },
    },
    spacing: {
      padding: true,
      units: ['px', '%', 'em', 'rem', 'vw', 'vh'],
    },
    typography: {
      customFontSize: false,
    },
  })
    .useTailwindColors()
    .useTailwindFontFamily()
    .useTailwindFontSize()
    .enable();

};

Relevant .budfiles

{
  "name": "sage",
  "private": true,
  "browserslist": [
    "extends @roots/browserslist-config"
  ],
  "engines": {
    "node": ">=16.0.0"
  },
  "type": "module",
  "scripts": {
    "dev": "bud dev",
    "build": "bud build",
    "translate": "yarn translate:pot && yarn translate:update",
    "translate:pot": "wp i18n make-pot . ./resources/lang/sage.pot --include=\"app,resources\"",
    "translate:update": "for filename in ./resources/lang/*.po; do msgmerge -U $filename ./resources/lang/sage.pot; done; rm -f ./resources/lang/*.po~",
    "translate:compile": "yarn translate:mo && yarn translate:js",
    "translate:js": "wp i18n make-json ./resources/lang --pretty-print",
    "translate:mo": "wp i18n make-mo ./resources/lang ./resources/lang",
    "build:critical": "critical index.php --penthouse-url=https://XXX.lndo.site --css public/css/app.*.css > public/css/critical.css"
  },
  "devDependencies": {
    "@roots/bud": "^6.16.0",
    "@roots/bud-purgecss": "^6.16.0",
    "@roots/bud-sass": "^6.16.0",
    "@roots/bud-tailwindcss": "^6.16.0",
    "@roots/sage": "6.16.0",
    "purgecss-with-wordpress": "^5.0.0"
  },
  "dependencies": {
    "@roots/bud-postcss": "^6.16.0",
    "alpinejs": "^3.12.0",
    "swiper": "^9.2.0",
    "sass": "^1.62.1"
  }
}

composer.json


{
  "name": "roots/sage",
  "type": "wordpress-theme",
  "license": "MIT",
  "description": "WordPress starter theme with a modern development workflow",
  "homepage": "https://roots.io/sage/",
  "authors": [
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    },
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "QWp6t",
      "email": "hi@qwp6t.me",
      "homepage": "https://github.com/qwp6t"
    },
    {
      "name": "Brandon Nifong",
      "email": "brandon@tendency.me",
      "homepage": "https://github.com/log1x"
    }
  ],
  "keywords": [
    "wordpress"
  ],
  "support": {
    "issues": "https://github.com/roots/sage/issues",
    "forum": "https://discourse.roots.io/"
  },
  "autoload": {
    "psr-4": {
      "App\\": "app/"
    }
  },
  "require": {
    "php": "^7.4|^8.0",
    "log1x/acf-composer": "^2.1",
    "log1x/navi": "^2.0",
    "log1x/poet": "^2.0",
    "roots/acorn": "^2.1"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "3.7.1"
  },
  "suggest": {
    "log1x/sage-directives": "A collection of useful Blade directives for WordPress and Sage (^1.0).",
    "log1x/sage-svg": "A useful SVG directive for inlining SVG's within Blade views (^1.0)."
  },
  "config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "sort-packages": true
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "scripts": {
    "lint": [
      "phpcs --extensions=php --standard=PSR12 app"
    ]
  },
  "extra": {
    "acorn": {
      "providers": [
        "App\\Providers\\ThemeServiceProvider"
      ]
    }
  }
}
kellymears commented 1 year ago

Transferring this to acorn repo.

QWp6t commented 1 year ago

What version of acorn are you using?

riccardomel commented 1 year ago

Hi i use: "roots/acorn": "^2.1"

riccardomel commented 1 year ago

Hi any news or something i can try? @QWp6t

retlehs commented 1 year ago

^2.1 isn't a specific version. v2.1.2? v2.1.1? v2.1.0? I'd suggest upgrading to the latest version of Acorn v3:

https://roots.io/acorn/docs/upgrading-acorn/

QWp6t commented 1 year ago

Try updating to Acorn v2.1.3 to see if that resolves it, otherwise upgrade to 3x and let us know if the bug persists with the latest version of Acorn.