Code Monkey home page Code Monkey logo

Comments (3)

kellymears avatar kellymears commented on July 22, 2024

bud.js doesn't ignore errors thrown by build dependencies.

The warning message you're seeing is emitted during bootstrapping when bud.js attempts to import config modules. At this very early stage bud.js will proceed even if a module can't be imported unless the module has bud in its filename. Since bud.js requires zero configuration it is important to throw early if a bud config is messed up. Otherwise, assuming zero config requirements are met (an entrypoint at @src/index.js), the build could succeed without any user config actually being applied.

In the case of a tailwind.config.js or tailwind.config.ts file with a syntax or import error, yes, bud.js will move beyond bootstrapping even without the module having been successfully loaded. But, tailwindcss/postcss should still throw. bud.js does nothing to mask a build error here.

For example, let's say we add a bad import statement:

import foo from './foo.js'; // does not exist

const config = {
  content: ['./index.php', './app/**/*.php', './resources/**/*.{php,vue,js}'],
  theme: {
    extend: {
      colors: {},
    },
  },
  plugins: [foo],
};

export default config;

As you point out, we can see that bud can't import this module but still keeps going:

[env] › registering expanded values /Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/.env
[env] › ◼  sourcing .env values Timer run for: 3ms
[fs] › ▶  Initializing filesystem Initialized timer...
[fs] › ▶  loading .pnpmfile.cjs Initialized timer...
[fs] › ◼  loading .pnpmfile.cjs Timer run for: 1ms
[fs] › ▶  loading tailwind.config.js Initialized timer...
[fs] [tailwind.config.js] › ⚠  tailwind.config.js causes an exception when imported.
Since tailwind.config.js does not appear to be a bud configuration file, bud.js is not throwing. Original error follows:

BudError: Cannot find module '/Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/foo.js' imported from /Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/tailwind.config.js
[fs] › ◼  Initializing filesystem Timer run for: 11ms
[bootstrap] › 🏗️ building sage

However, the build itself fails because tailwind throws:

╭─ ✘ sage ./public [5ecab747f4778a527a32]
│
├─ ✘  error
│
│  Cannot find module './foo.js'
│ Require stack:
│ - ./tailwind.config.ts
│
│
├─ ✘  error
│
│  Cannot find module './foo.js'
│ Require stack:
│ - ./tailwind.config.ts
│
│
├─ entrypoints
│  ├─ app
│  │  ├─ js/runtime.06fab3.js    1.05 kB
│  │  ├─ js/407.814868.js      314 bytes
│  │  └─ js/app.c4614b.js        8.17 kB
│  └─ editor
│     ├─ js/runtime.06fab3.js    1.05 kB
│     ├─ js/407.814868.js      314 bytes
│     └─ js/editor.fa098a.js      8.4 kB
│
╰─ compiled 12 modules in 537ms

[sage] [hooks] › ▶  compiler.close Initialized timer...
[sage] [hooks] › …  executing callback 1/2
[sage] [hooks] › …  executing callback 2/2
[sage] [hooks] › ✔  executing callback 1/2
[fs] › ▶  writing new checksums Initialized timer...
[fs] › ◼  writing new checksums Timer run for: 0ms
[sage] [hooks] › ✔  executing callback 2/2
[sage] [hooks] › ◼  compiler.close Timer run for: 3ms
error Command failed with exit code 1.

I think this is the correct behavior. A person may have a module lying around in the root of their project that is broken and cannot be imported. It shouldn't cause a total failure unless:

  1. the tooling depends on the module and throws an error
  2. a bud extension depends on the module and throws an error

An example of the second case is calling bud.wpjson.useTailwindColors() or a similar function. In this case we see a different error:

[sage] › processing base configuration bud.config.js
[sage] › processing as dynamic configuration: bud.config.js
[fs] › ▶  loading bud.config.js Initialized timer...
[fs] › ◼  loading bud.config.js Timer run for: 0ms

ConfigError

✘ Error in bud.config.js

BudError

✘ Cannot read properties of undefined (reading 'default')

☰ Stack trace
    at get config [as config] (node_modules/@roots/bud-tailwindcss/lib/extension/index.js:46:48)
    at BudTailwindCss.resolveThemeValue (node_modules/@roots/bud-tailwindcss/lib/extension/index.js:61:39)
    at WordPressThemeJSON.useTailwindColors
(node_modules/@roots/bud-tailwindcss-theme-json/lib/extension.js:24:78)
    at default (bud.config.js:62:6)

ℹ See file /Users/kellymears/code/git/roots/docker/bedrock/web/app/themes/sage/bud.config.js

error Command failed with exit code 1.

I can't reproduce a JS runtime error originating from the tailwind config that doesn't cause the process to exit with a non-zero error code. Do you mind sharing the tailwind config that should throw but doesn't?

from bud.

montchr avatar montchr commented on July 22, 2024

Thanks for the detailed response. Based on your logs, it certainly looks like Bud is doing what I would expect.

I'll follow up soon with a minimal example if I can re-reproduce the issue. After changing course away from attempting to importing a module (which did actually exist), I found that some of my changes to the Tailwind config were being heavily cached. I suspect that this caching issue may have prevented Tailwind from throwing an error properly.

For context, this happened when attempting to override the CSS output by the Tailwind Typography plugin, which generally needs to be done in the config file. That caching caused a lot of frustration but after realizing what was going on I made sure to clear cache and built assets each time I made a change (very slow, do not recommend).

from bud.

kellymears avatar kellymears commented on July 22, 2024

The issue you encountered with the sticky tailwind config caching is addressed in 6.12.1.

from bud.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.