Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot redefine property: fetch #3356

Closed
GauBen opened this issue Jan 15, 2022 · 4 comments
Closed

Cannot redefine property: fetch #3356

GauBen opened this issue Jan 15, 2022 · 4 comments

Comments

@GauBen
Copy link
Contributor

GauBen commented Jan 15, 2022

Describe the bug

I'm trying to import a built svelte-kit site within another one, and it is not possible because importing import { handler } from 'sub-site/build/handler' has side-effects, namely calling __fetch_polyfill.

Reproduction

  1. Create a svelte-kit website that uses adapter-node
  2. Build this website
  3. Create another svelte-kit website with the following configuration
import adapter from '@sveltejs/adapter-node'
import preprocess from 'svelte-preprocess'
import { handler } from 'sub-site/build/handler'

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: preprocess(),
  kit: {
    adapter: adapter(),
    target: '#svelte',
    vite: {
      plugins: [
        {
          name: 'sub-site',
          configureServer({ middlewares }) {
            middlewares.use(handler) // Load the sub-site here
          },
        },
      ],
    },
  },
}

export default config

Logs

> Cannot redefine property: fetch
    at Function.defineProperties (<anonymous>)
    at __fetch_polyfill (file:///home/.../node_modules/.pnpm/@sveltejs+kit@1.0.0-next.229_svelte@3.46.1/node_modules/@sveltejs/kit/dist/install-fetch.js:6494:9)

System Info

SvelteKit v1.0.0-next.229
Adapter Node v1.0.0-next.61

Severity

annoyance

Additional Information

I'll submit a PR in a few minutes that fixes this issue, the solution is to add configurable: true to all definitions here:

export function __fetch_polyfill() {
Object.defineProperties(globalThis, {
fetch: {
enumerable: true,
value: fetch
},
Response: {
enumerable: true,
value: Response
},
Request: {
enumerable: true,
value: Request
},
Headers: {
enumerable: true,
value: Headers
}
});
}

@GauBen
Copy link
Contributor Author

GauBen commented Jan 15, 2022

@Rich-Harris Could you please bump adapter-node to use kit v231?

@bluwy
Copy link
Member

bluwy commented Jan 16, 2022

#3357 that fixes this has been merged. Closing this.

Could you please bump adapter-node to use kit v231?

I'm not sure what you mean. adapter-node doesn't have a hard version on kit?

@bluwy bluwy closed this as completed Jan 16, 2022
@GauBen
Copy link
Contributor Author

GauBen commented Jan 16, 2022

I'm not sure what you mean. adapter-node doesn't have a hard version on kit?

That's right, but since adapter-node was built and published before #3357 was merged, the dist still contains the old __fetch_polyfill.

@bluwy
Copy link
Member

bluwy commented Jan 17, 2022

Ah I see. Looks like adapter vercel, node and netlify builds based on kit. I'll make a changeset for them so they get re-released. (#3377)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants