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

Is it possible for mjs to do process.mainModule === module? #320

Closed
ratson opened this issue Mar 16, 2018 · 5 comments
Closed

Is it possible for mjs to do process.mainModule === module? #320

ratson opened this issue Mar 16, 2018 · 5 comments
Labels

Comments

@ratson
Copy link

ratson commented Mar 16, 2018

I find #299 talking about exposing process.mainModule, but could not find an example using it.

When I tried node -r esm main.mjs

import _ from 'lodash'

const { sum } = _

export default sum

if (process.mainModule === module) {
  console.log(sum([1, 2]))
}

it gives ReferenceError: module is not defined

Is this use case not supported?

@jdalton
Copy link
Member

jdalton commented Mar 16, 2018

Hi @ratson!

What version of @std/esm or esm are you using?

@ratson
Copy link
Author

ratson commented Mar 16, 2018

How can I forget this. I am testing it with esm "^3.0.6".

@jdalton
Copy link
Member

jdalton commented Mar 16, 2018

Thanks @ratson!

In esm the .mjs file is locked down:

🔒 .mjs files are limited to basic functionality without support for esm options.

So to enable this you'll need to use .js.

@jdalton jdalton closed this as completed Mar 16, 2018
@ratson
Copy link
Author

ratson commented Mar 16, 2018

Thanks, @jdalton I got it working with node -r esm main.js.
Is that mean there is no equivalent for .mjs?

@jdalton
Copy link
Member

jdalton commented Mar 16, 2018

Is that mean there is no equivalent for .mjs?

Correct. .mjs is not fully baked yet so support is limited.
There is currently no process.mainModule support in .mjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants