Skip to content

ESBuild define option can break adapter-node assetsMiddleware #2581

Description

@arnivuo

Describe the bug

I switched from another adapter to use node adapter and had esbuild options with define. That basically overwrites esbuild_app_dir defined by the adapter breaking assetsMiddleware. A symptom is rather odd as all assets are responding to status code 500 with no clue why.

Maybe the adapter should warn the user if they overwrite the esbuild_app_dir property from define or the documentation could mention it. Now you can figure it out but it's not that obvious.

Reproduction

In svelte.config.js configure node adapter like:

adapterNode({
  esbuild(defaultOptions) {
    return {
      ...defaultOptions,
      define: {
        foo: 'bar'
      }
    };
  }
});

Build, run node build and check broken http://localhost:3000 site.

Fix is to do configuration e.g.:

adapterNode({
  esbuild(defaultOptions) {
    defaultOptions.define = {
      ...defaultOptions.define,
      foo: 'bar'
    }
    return defaultOptions;
  }
});

Logs

No response

System Info

System:
    OS: macOS 11.5.2
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
    Memory: 63.46 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.1 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.12 - /usr/local/bin/npm
  Browsers:
    Chrome: 94.0.4606.71
    Safari: 14.1.2
  npmPackages:
    @sveltejs/adapter-node: ^1.0.0-next.53 => 1.0.0-next.53
    @sveltejs/adapter-static: ^1.0.0-next.13 => 1.0.0-next.20
    @sveltejs/kit: 1.0.0-next.180 => 1.0.0-next.180
    svelte: ^3.34.0 => 3.43.1

Severity

annoyance

Additional Information

No response

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