Skip to content

Vercel Build Fails as Can't Set EsBuild Externals  #3588

Closed

Description

@cryptodeal

Describe the bug

My vercel build has been failing since the removal of the esBuild config options in @sveltejs/adapter-vercel.

I've continued developing using the following package versions (last working):

"@sveltejs/adapter-vercel": "1.0.0-next.32",
"@sveltejs/kit": "1.0.0-next.206",

However, that's definitely less than ideal as I'm continuing to build around an outdated API for both @sveltejs/kit & @sveltejs/adapter-vercel.

The dependency causing my build issues (@napi-rs/*) is a package required indirectly as a dependency of a package in a shared monorepo used in the frontend. (Backend defines db schema, controllers, autogen type definitions, etc. that are used both in the frontend and for writing real time data scraped from various sources to the db, hence the monorepo greatly streamlines the dev process).

I'd previously built the frontend project successfully using both Vite resolve.alias and via installing the pnpm symlinked version of the built package as a dependency during the build process (setting pnpm to shamefully-hoist when building on Vercel) using the following esBuild config options:

adapter({
  esbuild(defaultOptions) {
    return {
      ...defaultOptions,
      plugins: [],
      external: ['@napi-rs/*']
    };
  }
})

Following the breaking API changes, I've tested with updated versions of @sveltejs/kit & @sveltejs/adapter-vercel using at least the following Vite config settings (both individually and in varying combinations), but to no avail.

Vite Config Options Tested:

  vite.ssr.noExternal: ['@napi-rs/*']
  ssr.external:  ['@napi-rs/*']
  vite.optimizeDeps.exclude: ['@napi-rs/*']

(I think I'd tried setting it as a rollup external as well using Vite config options, but that also failed to resolve the issue)

Build always fails with the following error:

error: No loader is configured for ".node" files

Any solutions for getting this build to work with the latest versions of @sveltejs/kit and @sveltejs/adapter-vercel?

Reproduction

I'm more than happy to setup a minimal reproduction of the issue if necessary, but iirc this is something @Rich-Harris is aware of per the checklist in PR #2931.

Logs

No response

System Info

System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1
    Memory: 138.94 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.4.2 - ~/.nvm/versions/node/v16.4.2/bin/node
    Yarn: 1.22.11 - /opt/homebrew/bin/yarn
    npm: 7.18.1 - ~/.nvm/versions/node/v16.4.2/bin/npm
  Browsers:
    Brave Browser: 97.1.34.81
    Safari: 15.2
  npmPackages:
    @sveltejs/adapter-vercel: 1.0.0-next.32 => 1.0.0-next.32 
    @sveltejs/kit: 1.0.0-next.206 => 1.0.0-next.206 
    svelte: ^3.46.2 => 3.46.2

Severity

blocking an upgrade

Additional Information

No response

Activity

  1. cryptodeal commented on Jan 28, 2022

    @cryptodeal
    Author

    Related: #3306

  2. Rich-Harris commented on Jan 28, 2022

    @Rich-Harris
    Member

    Would an API like this work?

    import adapter from '@sveltejs/adapter-vercel';
    
    export default {
      adapter: adapter({
        external: ['@napi-rs/*']
      }),
      // ...
    };
  3. cryptodeal commented on Jan 28, 2022

    @cryptodeal
    Author

    @Rich-Harris, that should definitely resolve the issue!

  4. harlantwood commented on Apr 2, 2022

    @harlantwood

    I was struggling with the same issue in adapter-cloudflare -- eventually found out it has a similar API:

    import adapter from '@sveltejs/adapter-cloudflare'
    
    const config = {
      kit: {
        adapter: adapter({
          external: ['redis'],
        }),
      }
    }
    

    Note that external: ['redis/*'] did not work.

    Posting here for others who may be searching for this info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions