APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
942 stars 226 forks source link

`Could not resolve "node-fetch"` error with sveltekit & vite #309

Closed DetachHead closed 5 months ago

DetachHead commented 1 year ago

routes/+page.svelte

<script lang="ts">
    import { dereference } from "@apidevtools/json-schema-ref-parser";
</script>

svelte.config.js

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://kit.svelte.dev/docs/integrations#preprocessors
    // for more information about preprocessors
    preprocess: vitePreprocess(),

    kit: {
        adapter: adapter(),
    },
};

export default config;

vite.config.ts

import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';
import path from 'path';

const config: UserConfig = {
    plugins: [sveltekit()]
};

export default config;

output from vite dev

X [ERROR] Could not resolve "node-fetch"

    node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js:140:113:
      140 │             const { default: fetch, Request, Headers } = yield Promise.resolve().then(() => __importStar(require("node-fetch")));
          ╵                                                                                                                  ~~~~~~~~~~~~

  You can mark the path "node-fetch" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

12:12:43 pm [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/@apidevtools/json-schema-ref-parser/dist/lib/resolvers/http.js:140:113: ERROR: Could not resolve "node-fetch"
    at failureErrorWithLog (C:\Users\user\svelte-schema-form\node_modules\esbuild\lib\main.js:1604:15)
    at C:\Users\user\svelte-schema-form\node_modules\esbuild\lib\main.js:1056:28
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
joeythomaschaske commented 1 year ago

Any update on this? For now I'm manually including node-fetch as a dependency

jonluca commented 5 months ago

Fixed in v11