Install fails out of the box

failed to load config from /path/to/mysite.test/web/app/themes/mytheme/vite.config.js
error during build:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/util.js'
is not defined by "exports" in /path/to/mysite.test/web/app/themes/mytheme/node_modules/@wordpress/dependency-extraction-webpack-plugin/package.json imported from /path/to/mysite/web/app/themes/mytheme/node_modules/@roots/vite-plugin/dist/index.js

On a clean install of the latest roots/bedrock + roots/sage combo. Usual instructions followed as per Installing Sage WordPress Starter Theme | Sage Docs | Roots

Any ideas what is wrong?

Actually there is a mismatch in the import in @roots/vite-plugin/index.ts vs. the package.json exports definition in @wordpress/dependency-extraction-webpack-plugin/package.json

The import: @wordpress/dependency-extraction-webpack-plugin/lib/util.js

Export: "./lib/util": "./lib/util.js",

Once I changed the export to be "./lib/util.js": "./lib/util.js"the build completed fine (Note the change from ./lib/util to ./lib/util.js in the export key.

1 Like

Ah OK so my temporary patch is the wrong way round but this fix will sort things. Thanks for the heads up.

Just pushed a release. npm upgrade should do the trick.

Hmm, after upgrading a Sage theme (v11.0.1, created last Friday) from ⁠roots/vite-plugin version ⁠1.2.1 to ⁠1.2.3 (or even ⁠1.2.2), Vite throws an error:

bun run build                                          
$ vite build
failed to load config from /Users/dcsturm/wrk/packages/wp-themes/wp-theme-gastro-hl/vite.config.js
error during build:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/dcsturm/wrk/packages/wp-themes/wp-theme-sage/node_modules/@wordpress/dependency-extraction-webpack-plugin/lib/util' imported from /Users/dcsturm/wrk/packages/wp-themes/wp-theme-sage/node_modules/@roots/vite-plugin/dist/index.js
Did you mean to import "@wordpress/dependency-extraction-webpack-plugin/lib/util.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:859:10)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38)
    at #link (node:internal/modules/esm/module_job:208:49)
error: script "build" exited with code 1

At first, I thought Bun was the issue here, but this also occurs with npm. Rolling back to ⁠1.2.1 or changing the import back to

... from "@wordpress/dependency-extraction-webpack-plugin/lib/util.js";

in ⁠index.js resolves the error.

So, the PR fixes an error that never occurred in my setup, although I’m using ⁠@wordpress/[email protected]:

bun why @wordpress/dependency-extraction-webpack-plugin
@wordpress/[email protected]
  └─ @roots/[email protected] (requires ^6.27.0)
     └─ dev sage (requires 1.2.1)

Are we sure the reported issue matches all environments?

I’m not able to reproduce with either bun or npm :eyes:

I’m sorry — I had already deleted the ⁠node_modules folder but not the ⁠bun.lock file. After purging both and running ⁠bun i again, the build ran smoothly.

2 Likes