You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When disabling certain dependencies for a browser environment via the browser field in the package.json (supported in esbuild since 0.5.26, #238), esbuild raises an exception when building code that tries to import from the disabled dependency.
The expected behavior would be that the import succeeds, but resolves to an undefined value that can be checked for in client code. This is how Vite and Rollup handle it.
To reproduce, put this in a directory, run npm install and npm run build:
Here's a small bespoke plugin that works around this issue:
// esbuild breaks with NOPed imports (via 'browser' field in package.json),// (See https://github.com/evanw/esbuild/issues/3367). This is a small// plugin to work around this for the pdiiif dependency.constdisabledDeps=newSet(['node-fetch','jsdom','util','events','zlib','prom-client','color-convert','crypto']);constdisabledDepsFixerPlugin={name: 'disabled-dep-fix',setup(build){constfilter=newRegExp(`^(${Array.from(disabledDeps).join('|')})$`);// Intercept import paths that are in the set of disabled dependencies and// make them have an `undefined` default exportbuild.onResolve({ filter },({ path })=>{return{ path,namespace: 'disabled-dep-fix'}})build.onLoad({filter: /.*/,namespace: 'disabled-dep-fix'},()=>({contents: 'export default undefined;',resolveDir: process.cwd(),}));},}
When disabling certain dependencies for a browser environment via the
browser
field in thepackage.json
(supported in esbuild since 0.5.26, #238), esbuild raises an exception when building code that tries to import from the disabled dependency.The expected behavior would be that the import succeeds, but resolves to an
undefined
value that can be checked for in client code. This is how Vite and Rollup handle it.To reproduce, put this in a directory, run npm install and npm run build:
package.json:
index.js:
Or clone https://gist.github.com/jbaiter/e830fb9fd5b2de5bc9d8db341c91bf94
Trying to build the example with
npm run build
raises this error:The text was updated successfully, but these errors were encountered: