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

export node module as .mjs file #19

Closed
wants to merge 1 commit into from
Closed

Conversation

jaeh
Copy link

@jaeh jaeh commented May 22, 2020

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [?] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

this outputs an mjs file instead of a js file to node/module.mjs

@magic/core is using node 14.2.0 and mjs files without compilation, and, contrary to most build tools, nodejs is not capable to detect modules automagically when importing.

alternatively to this commit we could also set "type": "module", in package.json, but i would expect that to break some commonjs applications on older node versions.

please note: i do not have a commonjs application ready to test this in!

> @magic/[email protected] build /media/j/data/dev/magic/core
> NODE_ENV=production src/bin.mjs build

/media/j/data/dev/magic/core/node_modules/hyperapp-render/node/module.js:3
import { Readable } from 'stream';
^^^^^^

SyntaxError: Cannot use import statement outside a module
...

@codecov-commenter
Copy link

codecov-commenter commented May 22, 2020

Codecov Report

Merging #19 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #19   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          127       127           
  Branches        35        35           
=========================================
  Hits           127       127           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52c6b14...213b53c. Read the comment docs.

@frenzzy
Copy link
Member

frenzzy commented May 25, 2020

Thank you for the PR!
As far as I know not all the tools support .mjs extension yet.
I have another solution here: #20

@frenzzy
Copy link
Member

frenzzy commented May 25, 2020

Just released v3.4.0 with the fix. Thanks again!

@frenzzy frenzzy closed this May 25, 2020
@jaeh
Copy link
Author

jaeh commented May 25, 2020

@magic/core 0.0.76 is using 3.4.0 now,
only needed change was
import render from 'hyperapp-render'
to
import * as render from 'hyperapp-render'

thank you so much for all the work!

@jaeh jaeh deleted the mjs_modules branch May 25, 2020 21:09
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