Skip to content

Make Hugo work with ESBuild >= 0.8.21 #8189

@anthonyfok

Description

@anthonyfok

ESBuild 0.8.21 fixed evanw/esbuild#546 (Plugins don't seem to apply to entrypoints) in evanw/esbuild@05eaca4 (fix # 546: plugins now apply to entry points):

On-resolve plugins now apply to entry points (# 546)

Previously entry points were required to already be resolved to valid file system paths. This meant that on-resolve plugins didn't run, which breaks certain workflows. Now entry point paths are resolved using normal import resolution rules.

To avoid making this a breaking change, there is now special behavior for entry point path resolution. If the entry point path exists relative to the current working directory and the path does not start with ./ or ../, esbuild will now automatically insert a leading ./ at the start of the path to prevent the path from being interpreted as a node_modules package path. This is only done if the file actually exists to avoid introducing ./ for paths with special plugin-specific syntax.

... which unfortunately did introduced a breaking change:

Error: Error building site: JSBUILD: failed to transform "js/main.js" (application/javascript):
"/home/r/hugoTestProjectJSModImports/assets/js/main.js:1:23": Could not resolve "./lib"

See #8105 ("Do not merge: deps: Update to ESBuild v0.8.27") and the failed TestJSBuildWithNPM and TestJSBuild tests on GitHub Actions: https://github.com/gohugoio/hugo/runs/1627365570?check_suite_focus=true

See also #8141 (where Debian build of hugo_0.80.0-1 was broken due to premature building with ESBuild 0.8.28) for more information.

I am starting to study resource_transformers/js/build.go and/or resource_transformers/js/options.go in Hugo. Hope I can get it to work! :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions