N
Nuxt3mo ago
johnk

Type is completely ignored in generated mjs, causes Nuxt #imports issues

Hello, I am using nuxt-open-fetch and all was going well. However it randomly started breaking, and I found out it is because the OpenFetchClient type is completely ignored in the generated .mjs. First, in the nuxt console, I get this error
WARN [nuxt] #imports should be transformed with real imports. There seems to be something wrong with the imports plugin.
WARN [nuxt] #imports should be transformed with real imports. There seems to be something wrong with the imports plugin.
, then in the browser console I get this error
Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/nuxt-open-fetch/dist/runtime/fetch.mjs?v=ef996c48' does not provide an export named 'OpenFetchClient' (at imports.mjs:31:56)
Uncaught SyntaxError: The requested module '/_nuxt/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/nuxt-open-fetch/dist/runtime/fetch.mjs?v=ef996c48' does not provide an export named 'OpenFetchClient' (at imports.mjs:31:56)
. In the server it has the proper export of
export type OpenFetchClient<Paths> = <ReqT extends Extract<keyof Paths, string>, ....
export declare function openFetchRequestInterceptor(...)
export declare function createOpenFetch<Paths>(...)
export declare function fillPath(...)
export type OpenFetchClient<Paths> = <ReqT extends Extract<keyof Paths, string>, ....
export declare function openFetchRequestInterceptor(...)
export declare function createOpenFetch<Paths>(...)
export declare function fillPath(...)
, but in the browser, fetch.mjs has the content of just
export function openFetchRequestInterceptor(ctx) {
ctx.request = fillPath(ctx.request, ctx.options.path);
}
export function createOpenFetch(options, localFetch) {
return (url, opts) => {
opts = typeof options === "function" ? options(opts) : {
...options,
...opts
};
const $fetch = getFetch(url, opts, localFetch);
return $fetch(fillPath(url, opts?.path), opts);
};
}
function getFetch(url, opts, localFetch) {
if (import.meta.server && localFetch) {
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
if (isLocalFetch)
return localFetch;
}
return globalThis.$fetch;
}
export function fillPath(path, params = {}) {
for (const [k, v] of Object.entries(params))
path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
return path;
}
export function openFetchRequestInterceptor(ctx) {
ctx.request = fillPath(ctx.request, ctx.options.path);
}
export function createOpenFetch(options, localFetch) {
return (url, opts) => {
opts = typeof options === "function" ? options(opts) : {
...options,
...opts
};
const $fetch = getFetch(url, opts, localFetch);
return $fetch(fillPath(url, opts?.path), opts);
};
}
function getFetch(url, opts, localFetch) {
if (import.meta.server && localFetch) {
const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
if (isLocalFetch)
return localFetch;
}
return globalThis.$fetch;
}
export function fillPath(path, params = {}) {
for (const [k, v] of Object.entries(params))
path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
return path;
}
What do I do to make sure OpenFetchClient is kept in the generated .mjs?
1 Reply
johnk
johnkOP3mo ago
Anyone can help?
Want results from more Discord servers?
Add your server