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

call createRequire lazily #63

Closed
jimmywarting opened this issue Nov 24, 2021 · 8 comments
Closed

call createRequire lazily #63

jimmywarting opened this issue Nov 24, 2021 · 8 comments
Labels

Comments

@jimmywarting
Copy link

jimmywarting commented Nov 24, 2021

I have some success to load eslint using import('https://jspm.dev/eslint@7') and running it too without any eslint config file in the browser. (I'm using useEslintrc: false)

version 8 don't work as grate, think it boils down to this:

const require = createRequire(import.meta.url);

...and also the fact that jspm don't support dynamic require() very well...

the best thing would be to not use createRequire at all and... they should be loaded async with import() instead... but lets not be hanged up on this too much... cuz it require to much refactoring and breakage.

I think the quickest and easiest solution would be to do:

require = (...args) => createRequire(import.meta.url)(...args)

is this 👆 something you could quickly impl?


currently import('https://jspm.dev/eslint@7') dose not call any require().
i still have yet to figure out how to manually add some eslint plugin without using the rules config that are limited to plain objects.

@nzakas
Copy link
Member

nzakas commented Nov 24, 2021

I'm sorry, I can't tell from your description what it is you're trying to do and how such a change would help. Can you explain in more detail?

@jimmywarting
Copy link
Author

jimmywarting commented Nov 24, 2021

Trying to do this:
image

I guess the problem could be solved if you just don't call the module.createRequire(...) at all
importing createRequire from module and not doing anything with it initially would be fine.

That is why i'm suggesting a simple wrapper function that calls createRequire lazily (when needed)

@jimmywarting
Copy link
Author

think this code works fine:

// create require lazily to fix jspm
// eslint-disable-next-line func-style
let require = pkg => {
    require = createRequire(import.meta.url);
    return require(pkg);
};

@nzakas
Copy link
Member

nzakas commented Nov 25, 2021

I’m still having trouble understanding why you’d want to do such a thing. What’s the use case?

It also seems like this is a bug in JSPM?

@jimmywarting
Copy link
Author

yea, it's a bug with jspm...

my simple usecase is that i would like to import eslint in the browser using a cdn+import, this is the only bit that prevents me from being able to load eslint@8 from jspm

eslint@7 did not have any createRequire stuff

@ljharb
Copy link
Contributor

ljharb commented Nov 26, 2021

Is there an open issue on jspm about supporting createRequire?

@jimmywarting
Copy link
Author

created one 2 days ago: jspm/babel-plugin-transform-cjs-dew#15

@nzakas
Copy link
Member

nzakas commented Nov 27, 2021

We don’t intend to support loading the eslint package directly in the browser like this. Your best bet is to get jspm to fix the bug.

@nzakas nzakas closed this as completed Nov 27, 2021
@nzakas nzakas moved this to Complete in Triage Jan 3, 2023
@nzakas nzakas added this to Triage Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

3 participants