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

ES6+ module #185

Closed
tomexx opened this issue Jan 27, 2017 · 8 comments · Fixed by #350
Closed

ES6+ module #185

tomexx opened this issue Jan 27, 2017 · 8 comments · Fixed by #350

Comments

@tomexx
Copy link

tomexx commented Jan 27, 2017

It would be great if ES6+ modules were supported and user could simply import the modules in a standard way. Any plans to do that? Thanks

@pdubroy
Copy link
Contributor

pdubroy commented Mar 6, 2017

Sorry, I could have sworn I replied to this right after you opened it!

I'd be happy to support importing ohm as an ES6 module if it's not too big of a change. I don't yet know enough about ES6 modules though -- can you suggest what we'd need to do to support this?

@jedahan
Copy link

jedahan commented Feb 8, 2018

I made an example of how I'd like to use ohm, that uses rollup to build stuff.... but it doesn't work. I am not familiar enough with how ohm is structured, or how commonjs / es6 modules work to fix the test case error. https://github.com/jedahan/requiring-ohm

(node:35387) ExperimentalWarning: The ESM module loader is experimental.
TypeError: Cannot read property 'PExpr' of undefined
   at /Volumes/data/code/requiring-ohm/build/room.js:1469:10
    at Failure.getPExpr (/Volumes/data/code/requiring-ohm/build/room.js:2:65)
    at Object.<anonymous> (/Volumes/data/code/requiring-ohm/build/room.js:5:2)

It seems Failure is being inlined, so there is no this to refer to

@jedahan
Copy link

jedahan commented Feb 10, 2018

An update, after some digging it looks like replacing the util.inherits with a universal module would help as well

@pdubroy
Copy link
Contributor

pdubroy commented Aug 27, 2020

I've tested importing Ohm in Node, and it seems to work. So I'm going to close this, but please re-open if there is something specific that is not working.

@jedahan, I do not know enough about Rollup to be able to help here. If there is something specific we can change that would help, please open a new issue and I'll see what I can do.

@pdubroy pdubroy closed this as completed Aug 27, 2020
@7185
Copy link

7185 commented Jan 3, 2022

I have the following message in my Angular project:

...ActionParser.js depends on 'ohm-js'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

It seems ohm-js is not following the ES module standard, so maybe this issue could be reopened?

@pdubroy
Copy link
Contributor

pdubroy commented Jan 8, 2022

@7185 I'm working on a fix in #350. Could you please try install ohm-js@16.2.0-pre.esm and let me know if it fixes the problem?

@7185
Copy link

7185 commented Jan 8, 2022

@pdubroy It seems to fix the problem indeed, no more warning with that version

pdubroy added a commit that referenced this issue Jan 8, 2022
Fixes #185. Now that Ohm can be built with Rollup (see #344), we can ship a proper ES module via a Rollup build step.
@pdubroy
Copy link
Contributor

pdubroy commented Jan 8, 2022

@7185 Thanks for confirming!

I've just published ohm-js@16.2.0 with this.

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 a pull request may close this issue.

4 participants