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

module-type should not override shouldFetch #2426

Closed
wenerme opened this issue Sep 22, 2022 · 2 comments
Closed

module-type should not override shouldFetch #2426

wenerme opened this issue Sep 22, 2022 · 2 comments

Comments

@wenerme
Copy link
Collaborator

wenerme commented Sep 22, 2022

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

@wenerme wenerme changed the title system-node can not import json module-type should not override shouldFetch Sep 22, 2022
@wenerme
Copy link
Collaborator Author

wenerme commented Sep 22, 2022

final workaround

const orig = System.shouldFetch;
System.shouldFetch = (url) => {
  return orig(url) || url.startsWith('https://');
};

@wenerme
Copy link
Collaborator Author

wenerme commented Sep 25, 2022

fixed by #2427

@wenerme wenerme closed this as completed Sep 25, 2022
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

1 participant