Title: esbuild: Error when trying to load a file switched off by the `package.json/browser/*: false` · Issue #546 · unjs/unplugin · GitHub
Open Graph Title: esbuild: Error when trying to load a file switched off by the `package.json/browser/*: false` · Issue #546 · unjs/unplugin
X Title: esbuild: Error when trying to load a file switched off by the `package.json/browser/*: false` · Issue #546 · unjs/unplugin
Description: Environment Node.js: 20.11.1 and 24.8.0 (latest 24) esbuild: 0.25.8 and 0.25.10 (latest) postcss: 8.4.47 and 8.5.6 (latest) Reproduction Run npm install esbuild unplugin postcss. Write the build script using esbuild, namely build.mjs. im...
Open Graph Description: Environment Node.js: 20.11.1 and 24.8.0 (latest 24) esbuild: 0.25.8 and 0.25.10 (latest) postcss: 8.4.47 and 8.5.6 (latest) Reproduction Run npm install esbuild unplugin postcss. Write the build sc...
X Description: Environment Node.js: 20.11.1 and 24.8.0 (latest 24) esbuild: 0.25.8 and 0.25.10 (latest) postcss: 8.4.47 and 8.5.6 (latest) Reproduction Run npm install esbuild unplugin postcss. Write the build sc...
Opengraph URL: https://github.com/unjs/unplugin/issues/546
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"esbuild: Error when trying to load a file switched off by the `package.json/browser/*: false`","articleBody":"### Environment\n\nNode.js: 20.11.1 and 24.8.0 (latest 24)\nesbuild: 0.25.8 and 0.25.10 (latest)\npostcss: 8.4.47 and 8.5.6 (latest)\n\n### Reproduction\n\nRun `npm install esbuild unplugin postcss`.\n\nWrite the build script using esbuild, namely `build.mjs`.\n\n```js\nimport { build } from 'esbuild';\nimport { createUnplugin } from 'unplugin';\n\nconst plugin = createUnplugin(() => ({\n name: 'passthru',\n transform: {\n handler(code) {\n return { code };\n }\n }\n}));\n\nbuild({\n bundle: true,\n entryPoints: ['./index.ts'],\n platform: 'browser',\n plugins: [plugin.esbuild()]\n});\n```\n\nWrite the entry point file, namely `index.ts`.\n\n```ts\nimport 'postcss/lib/input';\n```\n\nThen, run the build script, `node ./build.mjs`. It will error out.\n\n```\n✘ [ERROR] ENOENT: no such file or directory, open '/workspaces/.../node_modules/postcss/lib/terminal-highlight' [plugin passthru]\n\n node_modules/esbuild/lib/main.js:1267:21:\n 1267 │ let result = await callback({\n ╵ ^\n\n at async open (node:internal/fs/promises:642:25)\n at async Object.readFile (node:internal/fs/promises:1279:14)\n at async Object.getContents (file:///workspaces/.../node_modules/unplugin/dist/index.js:1070:34)\n at async file:///workspaces/.../node_modules/unplugin/dist/index.js:1172:16\n at async file:///workspaces/.../node_modules/unplugin/dist/index.js:1073:23\n at async requestCallbacks.on-load (/workspaces/.../node_modules/esbuild/lib/main.js:1267:22)\n at async handleRequest (/workspaces/.../node_modules/esbuild/lib/main.js:628:11)\n```\n\n### Describe the bug\n\nOneliner: esbuild/unplugin trying to load packages with some files turned off via `package.json/browser`, esbuild send a extension-less `args.path` to unplugin, and unplugin failed to read the file via `fs.readFile`. `postcss` is one of the packages with \"turned off\" files.\n\nIn `postcss/package.json`, it has `browser` field to \"turn off\" some files. Excerpt:\n\n```json\n{\n \"browser\": {\n \"./lib/terminal-highlight\": false,\n \"source-map-js\": false,\n \"path\": false,\n \"url\": false,\n \"fs\": false\n }\n}\n```\n\nunplugin trying to load `postcss/lib/terminal-highlight` as instructed by `esbuild`. However, the `terminal-highlight` file is \"turned off\" in the `package.json`.\n\nesbuild sends the following `args` object to unplugin, and unplugin try to load it via `fs.promises.readFile` [(Code)](https://github.com/unjs/unplugin/blob/main/src/esbuild/index.ts#L120):\n\n```js\n{\n path: '/workspaces/BotFramework-WebChat/node_modules/postcss/lib/terminal-highlight',\n namespace: 'file',\n suffix: '',\n pluginData: undefined,\n with: {}\n}\n```\n\nThe `args.path` does not contains any file extension because the file is \"turned off\" in `package.json`.\n\nunplugin failed to load the file, resulting in an error and bubbled up.\n\n### Additional context\n\nThe scenario is specific to how unplugin load a file.\n\nesbuild do not have a way for plugin to \"request esbuild to load a file\". So most esbuild plugins will try to load files themselves. Plugins which do this should be careful about esbuild not sending the file extension for files in some cases.\n\n### Logs\n\n```sh\n\n```","author":{"url":"https://github.com/compulim","@type":"Person","name":"compulim"},"datePublished":"2025-09-18T02:57:18Z","url":"https://github.com/unjs/unplugin/issues/546"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5f6d32cc-bcfd-50a1-6f13-7b2a78a1b9c4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D862:832A2:2B17F2:3ABB4C:6B0069D5 |
| html-safe-nonce | 051a562070471823deb08eff9be1ec34a47051cd5e54238985a1a1c66ffc950f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODYyOjgzMkEyOjJCMTdGMjozQUJCNEM6NkIwMDY5RDUiLCJ2aXNpdG9yX2lkIjoiMzkxNzc1MTU2MDExNjkyMjgzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2ebbe158816cf5da97e0aa36699d527095ba382b2298304612449171be9c7883 |
| hovercard-subject-tag | issue:3428453963 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/unjs/unplugin/546/issue_layout |
| twitter:image | https://opengraph.githubassets.com/efd70e14edeafc581b574bf772ea7fa46b770cc9edd4b8da083e57fada5bb609/unjs/unplugin/issues/546 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/efd70e14edeafc581b574bf772ea7fa46b770cc9edd4b8da083e57fada5bb609/unjs/unplugin/issues/546 |
| og:image:alt | Environment Node.js: 20.11.1 and 24.8.0 (latest 24) esbuild: 0.25.8 and 0.25.10 (latest) postcss: 8.4.47 and 8.5.6 (latest) Reproduction Run npm install esbuild unplugin postcss. Write the build sc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | compulim |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/unjs/unplugin git https://github.com/unjs/unplugin.git |
| octolytics-dimension-user_id | 80154025 |
| octolytics-dimension-user_login | unjs |
| octolytics-dimension-repository_id | 385261169 |
| octolytics-dimension-repository_nwo | unjs/unplugin |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 385261169 |
| octolytics-dimension-repository_network_root_nwo | unjs/unplugin |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width