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

Get self reference modules working #1

Merged
merged 1 commit into from
Nov 26, 2019

Conversation

MylesBorins
Copy link
Contributor

I was partially confused due to a potential spec bug
in package.exports that didn't take into account top-level
application (without a . main)

This now works and has a passing test.

Refs: nodejs/node#30633

I was partially confused due to a potential spec bug
in package.exports that didn't take into account top-level
application (without a . main)

This now works and has a passing test.

Refs: nodejs/node#30633
@DerekNonGeneric
Copy link
Owner

DerekNonGeneric commented Nov 25, 2019

@MylesBorins, I cloned your branch and ran the test locally. It is failing on my machine. Could this have to do with the ~/package.json hack? (I don't have one.)

@MylesBorins
Copy link
Contributor Author

MylesBorins commented Nov 25, 2019 via email

@DerekNonGeneric DerekNonGeneric merged this pull request into DerekNonGeneric:master Nov 26, 2019
@DerekNonGeneric
Copy link
Owner

I will take it from here and investigate further, thanks!

@fusionstrings
Copy link

Hi @MylesBorins and @DerekNonGeneric

I ended up here while following the trails of LOAD_SELF_REFERENCE from here https://nodejs.org/dist/latest-v13.x/docs/api/modules.html and nodejs/node#31009

I was looking into the implementation to get help on my quest to get 'self reference" working from here https://github.com/MylesBorins/lorem-demo/tree/fc5ed2558670028e3c5bb02f2ae098044d63212a

The implementation uses --no-esm and test fails in absence of it. Does it mean that self resolution is non-ESM feature?

@DerekNonGeneric
Copy link
Owner

Hello @fusionstrings, glad you found your way here!

Does it mean that self resolution is non-ESM feature?

Nope, it definitely works with import too!

Here's a brief explanation that might help clarify what's being described above.

The --no-esm flag disables '-r esm' behavior by switching off the --esm flag, which is on by default. This '-r esm' behavior would preload the esm module at startup. The esm, module, which is a userland loader to polyfill versions of Node.js without native support for ES Modules, is no longer necessary in v13.2+. This is because the majority of the ES module implementation is unflagged in the 13.x release line.

I would recommend checking out the master branch of this repository (the one attached to this thread) to see a currently functional implementation. Just make sure you're on v13.2+. It should be working! I know how confusing this can be, so I've dropped some links below that I hope will clarify what I've written above. Ultimately, the cause of it not working on my end was that the integrated VSCode terminal, which I was using to test this behavior, was using the wrong version.

Let me know if there's anything else. :)

  • --no-esm §
  • -r, --require module §
  • esm, module §
  • v13.2 Unflagging announcement §

Note: the esm module does not put your code in module context. It is still in commonjs context, and I would advise against using it if you are interested in testing the new ES module implementation.

@fusionstrings
Copy link

Thanks a lot @DerekNonGeneric for explaining in detail especially about significance of --no-esm.

I got it working now 👍

@MylesBorins
Copy link
Contributor Author

MylesBorins commented Feb 24, 2020 via email

@fusionstrings
Copy link

@MylesBorins Thanks for clarifying.

The issue with me was extremely weird. I matched with the code in master branch of https://github.com/DerekNonGeneric/loader339 and my code was using same convention.

As @DerekNonGeneric mentioned that he was using VSCode integrated terminal, so was I.
I use nvm and ensured correct version was activated.

I still can't figure out what was wrong 😢but a restart seems to have fixed it for me.
Assurance that master branch has working code ensured that something is wrong from my side.

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

Successfully merging this pull request may close these issues.

3 participants