Development build (yarn dev) is not working in sage 10

Hi,

I have created a fresh sage theme in Ubuntu OS. I used the following command to create/setup sage project:

composer create-project roots/sage sage10

Then I added Acorn by running the following command inside themes root directory

composer require roots/acorn

After enabling the acorn I ran the following commands:

yarn install
yarn bud upgrade
yarn build

Here, how I configured my bud.config.js file

/**
 * Compiler configuration
 *
 * @see {@link https://roots.io/docs/sage sage documentation}
 * @see {@link https://bud.js.org/guides/configure bud.js configuration guide}
 *
 * @type {import('@roots/bud').Config}
 */
export default async (app) => {
  /**
   * Application assets & entrypoints
   *
   * @see {@link https://bud.js.org/docs/bud.entry}
   * @see {@link https://bud.js.org/docs/bud.assets}
   */
  app
    .entry('app', ['@scripts/app', '@styles/app'])
    .entry('editor', ['@scripts/editor', '@styles/editor'])
    .assets(['images']);

  /**
   * Set public path
   *
   * @see {@link https://bud.js.org/docs/bud.setPublicPath}
   */
  app.setPublicPath('/wp-content/themes/sage10/public/');

  /**
   * Development server settings
   *
   * @see {@link https://bud.js.org/docs/bud.setUrl}
   * @see {@link https://bud.js.org/docs/bud.setProxyUrl}
   * @see {@link https://bud.js.org/docs/bud.watch}
   */
  app
    .setUrl('http://localhost:3000')
    .setProxyUrl('http://localhost:10003')
    .setPublicUrl('http://localhost:10003')
    .watch(['resources/views', 'app']);

  /**
   * 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}
   */
  app.wpjson
    .setSettings({
      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();
};

I’m using local by Flywheel for local WordPress environment. Attaching below the settings of local

It’s all about setup. Now let’s come to the issue, When I start the development server by running the command yarn dev my app.js file is not getting compiled i.e. none of the code written in app.js is working. Also, can’t see any error log either in the dev build or even in the browsers console.

Here is the dev build status:

 sage [ac0e99637c4e7bed]                                                             ./public
│
│ app
│  ◉ js/runtime.js                                                                    49.14 kB
│  ◉ js/app.js                                                                        136.5 kB
│
│ editor
│  ◉ js/runtime.js                                                                    49.14 kB
│  ◯ js/editor.js                                                                    127.32 kB
│
╰ 134ms 114 modules [97/114 modules cached]

 Network

 › Proxy  ┄ http://localhost:10003/
 › Dev    ┄ http://localhost:3000/
          ┄ http://192.168.0.102:3000/

But when I run yarn build app.js file is working. Now after the build if I make any changes in the app.js file again stops working.
I tried to debug this by adding log statements in app.js file, In dev environment nothing is getting logged to the browsers console. It works only when I make a build.

So, In a summary app.js file or any other js file is not working in dev environment. It only works when I make the final build using yarn build.

I can’t able to figure this out. Don’t know where the issue is exactly. Can anyone please help me into this? Any help is much appreciated!

Thanks!

Howdy! I’d start by using a proper hostname for your dev site, like example.local instead of localhost:10003

Yeah. Because some other services are already running on 8080 port in my system that’s why I need to use localhost. But I tried with the proper hostname as well and having the exact same issue with the router mode as site domain.

Can you share your latest Bud config with the URL settings?

Hey Ben im kinda having the same issue as Bhanu. My issue is I run “yarn dev” there’s no styling and js doesn’t work on the dev url but when I run “yarn build”, the styling and js work. How do I make styles and js work in development/when I run “yarn dev”? Thanks.

I’m using ubuntu on baremetal on my local pc. In bud.config.js the only thing i changed is the proxyUrl:

     .setUrl('http://localhost:3000')
    .setProxyUrl('http://myname.local')
    .watch(['resources/views', 'app'])

This has been an issue since 6.18.0. I have two Bootstrap based projects with the same results.

Running Nginx & WP on Docker with the following Bud config:

/**
 * Compiler configuration
 *
 * @see {@link https://roots.io/docs/sage sage documentation}
 * @see {@link https://bud.js.org/guides/configure bud.js configuration guide}
 *
 * @type {import('@roots/bud').Config}
 */
export default async (app) => {
  /**
   * Application assets & entrypoints
   *
   * @see {@link https://bud.js.org/docs/bud.entry}
   * @see {@link https://bud.js.org/docs/bud.assets}
   */
  app
    .entry('app', ['@scripts/app', '@styles/app'])
    .entry('editor', ['@scripts/editor', '@styles/editor'])
    .assets(['images']);

  /**
   * Set public path
   *
   * @see {@link https://bud.js.org/docs/bud.setPublicPath}
   */
  app.setPublicPath('/wp-content/themes/kp/public/');

  /**
   * Development server settings
   *
   * @see {@link https://bud.js.org/docs/bud.setUrl}
   * @see {@link https://bud.js.org/docs/bud.setProxyUrl}
   * @see {@link https://bud.js.org/docs/bud.watch}
   */
  app
    .setUrl('https://localhost:3000')
    .setProxyUrl('https://kp.local')
    .watch(['resources/views', 'app']);

  /**
   * 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}
   */
  app.wpjson
    .setSettings({
      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,
      },
    });
};

Installed packages:

sage@ /Users/jay/Projects/kp/wordpress/wp-content/themes/kp

├── @popperjs/core@2.11.8
├── @roots/bud-sass@6.19.1
├── @roots/bud-stylelint@6.19.1
├── @roots/bud@6.19.1
├── @roots/sage@6.19.1
└── bootstrap@5.3.2

The console output when running npm run dev looks normal:

> dev
> bud dev


╭ sage [6f70d4b09750a914]                                                                        ./public
│
│ app
│  ◯ js/runtime.js                                                                                49.2 kB
│  ◯ js/app.js                                                                                    1.11 MB
│
│ editor
│  ◯ js/runtime.js                                                                                49.2 kB
│  ◯ js/editor.js                                                                               835.75 kB
│
│ assets
│  ◯ images/icons/icon-arrow-right.svg                                                          500 bytes
│  ◯ images/icons/icon-calendar.svg                                                             420 bytes
│  ◯ images/icons/icon-li.svg                                                                   380 bytes
│  ◯ images/icons/icon-clock.svg                                                                311 bytes
│  ◯ images/icons/icon-fb.svg                                                                   245 bytes
│  … 12 additional assets not shown
│
╰ 249ms 196 modules [196/196 modules cached]

 Network

 › Proxy  ┄ https://kp.local/
 › Dev    ┄ http://localhost:3000/
          ┄ http://192.168.1.4:3000/

 Press h to show help

I previously worked around by this by downgrading back to 6.17.0, but since 6.19.0 or 6.19.1 rolling back resulted in some react related errors even when restoring a previously working project from a .zip file.

Same problem - fresh install of sage 10 with bud 6.19.1.
When I do a fresh install of Sage 10 - it comes with the 6.16.1 - but that can’t run due to an error.

My config is as follow

/**
 * Compiler configuration
 *
 * @see {@link https://roots.io/docs/sage sage documentation}
 * @see {@link https://bud.js.org/guides/configure bud.js configuration guide}
 *
 * @type {import('@roots/bud').Config}
 */
export default async (app) => {
  /**
   * Application assets & entrypoints
   *
   * @see {@link https://bud.js.org/docs/bud.entry}
   * @see {@link https://bud.js.org/docs/bud.assets}
   */
  app
    .entry('app', ['@scripts/app', '@styles/app'])
    .entry('editor', ['@scripts/editor', '@styles/editor'])
    .assets(['images']);

  /**
   * Set public path
   *
   * @see {@link https://bud.js.org/docs/bud.setPublicPath}
   */
  app.setPublicPath('/app/themes/sage/public/');

  /**
   * Development server settings
   *
   * @see {@link https://bud.js.org/docs/bud.setUrl}
   * @see {@link https://bud.js.org/docs/bud.setProxyUrl}
   * @see {@link https://bud.js.org/docs/bud.watch}
   */
  app
    .setUrl('http://localhost:3000')
    .setProxyUrl('http://carlog.test')
    .watch(['resources/views', 'app']);

  /**
   * 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}
   */
  app.wpjson
    .setSettings({
      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();
};

Yes Sure.

Here is my latest bud config after using the proper hostname

/**
 * Compiler configuration
 *
 * @see {@link https://roots.io/docs/sage sage documentation}
 * @see {@link https://bud.js.org/guides/configure bud.js configuration guide}
 *
 * @type {import('@roots/bud').Config}
 */
export default async (app) => {
  /**
   * Application assets & entrypoints
   *
   * @see {@link https://bud.js.org/docs/bud.entry}
   * @see {@link https://bud.js.org/docs/bud.assets}
   */
  app
    .entry('app', ['@scripts/app', '@styles/app'])
    .entry('editor', ['@scripts/editor', '@styles/editor'])
    .assets(['images']);

  /**
   * Set public path
   *
   * @see {@link https://bud.js.org/docs/bud.setPublicPath}
   */
  app.setPublicPath('/wp-content/themes/sage10/public/');

  /**
   * Development server settings
   *
   * @see {@link https://bud.js.org/docs/bud.setUrl}
   * @see {@link https://bud.js.org/docs/bud.setProxyUrl}
   * @see {@link https://bud.js.org/docs/bud.watch}
   */
  app
    .setUrl('http://localhost:3000')
    .setProxyUrl('http://test.local')
    .setPublicUrl('http://test.local:10003')
    .watch(['resources/views', 'app']);

  /**
   * 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}
   */
  app.wpjson
    .setSettings({
      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();
};

And here is my local settings

I’m still facing the same issue using @roots/bud 6.19.1 and sage 10.7.0

I’m not sure I follow what this port is for

Is your test.local site setup with SSL? If so, you’ll need to use https as the protocol in your Bud config, and since you’re using Local you’ll also need to define the path to your certs

See https://github.com/roots/bud/issues/2529#issuecomment-1860710225 for an example

No. My local site is not setup with SSL. Do we need to enable for SSL for local site?
If so, I will give it a try.

After making a complete fresh setup with just some changes. I’m now able to make this work for me. I made the following changes with this fresh installation.

  1. I tried to enable SSL from local. Please look into the attached screenshot below.

  1. Current bud.config.js file
/**
 * Compiler configuration
 *
 * @see {@link https://roots.io/docs/sage sage documentation}
 * @see {@link https://bud.js.org/guides/configure bud.js configuration guide}
 *
 * @type {import('@roots/bud').Config}
 */
export default async (app) => {
  /**
   * Application assets & entrypoints
   *
   * @see {@link https://bud.js.org/docs/bud.entry}
   * @see {@link https://bud.js.org/docs/bud.assets}
   */
  app
    .entry('app', ['@scripts/app', '@styles/app'])
    .entry('editor', ['@scripts/editor', '@styles/editor'])
    .assets(['images']);

  /**
   * Set public path
   *
   * @see {@link https://bud.js.org/docs/bud.setPublicPath}
   */
  app.setPublicPath('/app/themes/sage10/public/');

  /**
   * Development server settings
   *
   * @see {@link https://bud.js.org/docs/bud.setUrl}
   * @see {@link https://bud.js.org/docs/bud.setProxyUrl}
   * @see {@link https://bud.js.org/docs/bud.watch}
   */
  app
    .setUrl('http://localhost:3000')
    .setProxyUrl('http://test.local')
    .watch(['resources/views', 'app']);

  /**
   * 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}
   */
  app.wpjson
    .setSettings({
      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();
};

Then I simply run the command below:

yarn install
yarn bud upgrade
yarn build

My current setup is working fine for CSS and JS changes. But it’s not working for react.
As soon as I add import statement for importing a react component to app.js file, browsers console throws an error:

ReferenceError: $RefreshReg$ is not defined

I tried to add dev and production dependencies. Here is my pacakage.json file after adding react depenedencies:

{
  "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": "wp i18n update-po ./resources/lang/sage.pot ./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"
  },
  "devDependencies": {
    "@roots/bud": "6.20.0",
    "@roots/bud-babel": "6.20.0",
    "@roots/bud-react": "6.20.0",
    "@roots/bud-tailwindcss": "6.20.0",
    "@roots/sage": "6.20.0"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}

I supposed that there is default react support in sage 10 as it was supported for tailwind :face_with_peeking_eye:. But anyways, If anything else is needed to add a support for react please let me know. I already tried with adding @roots/bud-react and @roots/bud-babel. Also added production dependancy for react and react-dom.

Thanks

Since your configuration issues are resolved, please make a new topic for your new issue and include the actual JavaScript code you’re attempting to use

For the other folks in this topic, if your dev server is not working correctly then triple check that your Bud config’s URL and proxy URL are set correctly based on your local dev environment

We have both CI tests and manually test each Bud release to make sure that HMR works — HMR hasn’t been broken in a Bud release in a year at this point. We also test across multiple setups with both SSL and non-SSL: vanilla Docker, Local, Lando, DDEV, and Trellis