folke / esbuild-runner

⚡️ Super-fast on-the-fly transpilation of modern JS, TypeScript and JSX using esbuild
https://www.npmjs.com/package/esbuild-runner
Apache License 2.0
712 stars 24 forks source link

Configuration option external is ignored #23

Closed vieira closed 3 years ago

vieira commented 3 years ago

Hello,

I tried defining pg-native as an external dependency but it seems the option is ignored, i.e., not being merged with the computed externals here:

https://github.com/folke/esbuild-runner/blob/5f005db17becd14cdfe2025c41b82f2bc9d19d9e/src/esbuild.ts#L94

My esbuild-runner.config.js:

module.exports = {
  type: 'bundle',
  esbuild: {
    external: ['pg-native'],
  },
}

and the error that is produced when running:

 > ../../node_modules/pg/lib/native/client.js:4:21: error: Could not resolve "pg-native" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    4 │ var Native = require('pg-native')
      ╵                      ~~~~~~~~~~~

/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1466
  let error = new Error(`${text}${summary}`);
              ^
Error: Build failed with 1 error:
../../node_modules/pg/lib/native/client.js:4:21: error: Could not resolve "pg-native" (mark it as external to exclude it from the bundle, or surround it with try/catch to handle the failure at run-time)
    at failureErrorWithLog (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1466:15)
    at /Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1148:28
    at runOnEndCallbacks (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1066:65)
    at buildResponseToResult (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1146:7)
    at /Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1253:14
    at /Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:629:9
    at handleIncomingPacket (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:726:9)
    at readFromStdout (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:596:7)
    at runServiceSync (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1831:3)
    at Object.buildSync (/Users/vieira/Code/f1/node_modules/esbuild/lib/main.js:1651:3)

I should note that I am using npm7 workspaces and that pg-native is a dependency of a dependency of another package in the workspace, if I add the dependency directly to the package.json of the package I am trying to run it works (the externals computation finds it).

folke commented 3 years ago

The reason is that we take all deps and devdeps from your package.json and put those as externals. I'll change it so you can additionally pass in any other externals as you do right now.

folke commented 3 years ago

I just released a new version where your external config should now work as expected. Thank you for reporting!