-
Notifications
You must be signed in to change notification settings - Fork 19
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
Invalid check in esmockIsLoader.js #178
Comments
Loader's will use separate thread wout access to that global object nodejs/node#44710 Would something like this work for indirect loading? What do you think? import esmock from 'esmock'
esmock.isLoaderRequired = false
esmock(...args) |
another way might be to support a call like this, where the options param defines "isLoaderRequired" as false, esmock('./module.js', defs, globaldefs, {
isLoaderRequired: false
}) |
What is the reason to check? For my understanding, it was created to avoid setup mistakes (for users) and to make predictable environment (for author). So, this check in not about particular Node parameters / esmock module in general, it's about esmock resolve/load hooks (both!) are loaded by Node engine. How to achieve that? I see 2 obvious options:
Personally, I prefer option 2 because it guarantee that we have 2 hooks and they know about esmock. Can it be a fake? Sure. Can it happen by mistake? No. |
importing and using "load" and "resolve" hooks will not result in the error message. esmock throws the error here, when esmock is called as a function only https://github.com/iambumblehead/esmock/blob/master/src/esmock.js#L6-L7 if (!esmockIsLoader())
throw new Error('process must be started with --loader=esmock') maybe I am misunderstanding your message, but easiest for esmock is to disable the message when called this way esmock('./module.js', defs, globaldefs, { isLoaderDetection: false }) and inside esmock if (opts.isLoaderDetection !== false && !esmockIsLoader())
throw new Error('process must be started with --loader=esmock') |
I mean that esmockIsLoader() implementation is a bit naive, and relates on way how to loader added to Node loaders chain. And my proposal is to use direct interaction with 'black box' (Node + any number of loaders), by use the following code in esmockIsLoader:
If esmock hooks were loaded, they will handle this request (yes, few lines of code are required) and return something to 'xxx' variable (just for example). 100% guaranteed, right? |
@koshic an interesting and clever idea :) yes I like that |
Yep, it's an unblockable pipe between loaders & 'user space'. |
changes are published and deployed https://github.com/iambumblehead/esmock/releases/tag/v2.0.7 |
esmock/src/esmockIsLoader.js
Line 1 in 5dfe486
What if esmock loaded indirectly, as part of other loader?
Error: process must be started with --loader=esmock
I suggest to set flag in global object inside resolve / load, or something like that.
The text was updated successfully, but these errors were encountered: