module-type should not override shouldFetch
wenerme opened this issue · comments
陈杨文 commented
Demonstration
Code Sandbox:
await import('systemjs/dist/system-node.cjs');
// ok
console.log(await globalThis.System.import('https://unpkg.com/@wener/utils@1.1.2/dist/system/index.min.js'));
// not ok
console.log(await globalThis.System.import('https://unpkg.com/@wener/utils@1.1.2/package.json'));
workaround by using module-types.js
// polyfill for module-types
if (typeof globalThis.fetch === 'undefined') {
const { default: fetch } = await import('node-fetch');
const { Response, Headers, Request, AbortError, FetchError, FormData, Blob, File } = await import('node-fetch');
Object.assign(globalThis, {
fetch,
Response,
Headers,
Request,
AbortError,
FetchError,
FormData,
Blob,
File,
});
}
await import('systemjs/dist/system-node.cjs');
await import('systemjs/dist/extras/module-types.js');
// ok
console.log(await globalThis.System.import('https://unpkg.com/@wener/utils@1.1.2/package.json'));
// not ok
console.log(await globalThis.System.import('https://unpkg.com/@wener/utils@1.1.2/dist/system/index.min.js'));
due to shouldFetch override, module-types prevents the node-fetch to load the js
Expected Behavior
works as expected
Actual Behavior
陈杨文 commented
final workaround
const orig = System.shouldFetch;
System.shouldFetch = (url) => {
return orig(url) || url.startsWith('https://');
};