mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
16.94k stars 954 forks source link

Bun build failed: SyntaxError: Unexpected keyword 'export' #2772

Open approached opened 10 months ago

approached commented 10 months ago

Describe the bug Not possible to build via bun.

To Reproduce

  1. Create a file:
    
    import mjml2html from "mjml";

/ Compile an mjml string / const htmlOutput = mjml2html( `

Hello World!

`, );

/ Print the responsive HTML generated and MJML errors if any / console.log(htmlOutput);

2. Build
```sh
bun build --sourcemap=external --target=bun ./src/test.ts --outdir ./build && bun run ./build/test.js

Expected behavior

  test.js        3076.02 KB

  test.js.map    5568.02 KB

[107ms] bundle 665 modules
SyntaxError: Unexpected keyword 'export'
      at .../api/build/test.js:70860
error: script "testfile" exited with code 1 (SIGHUP)

Line 70860:

  exports.FILES = [
    "......../api/node_modules/uglify-js/tools/exports.js"
  ];
  new Function("domprops", "exports", function() {
    var code = exports.FILES.map(function(file) {
      return fs.readFileSync(file, "utf8");
    });
    code.push("exports.describe_ast = " + describe_ast.toString());
    return code.join("\n\n");
  }())(require_domprops(), exports);
  if (+process.env["UGLIFY_BUG_REPORT"]) {
    var $minify = function(files, options) {
      if (typeof options == "undefined")
        options = "<<undefined>>";
      var code = [
        "// UGLIFY_BUG_REPORT",
        to_comment(options)
      ];
      if (typeof files == "string") {
        code.push("");
        code.push("//-------------------------------------------------------------");
        code.push("// INPUT CODE", files);
      } else
        for (var name in files) {
          code.push("");
          code.push("//-------------------------------------------------------------");
          code.push(to_comment(name), files[name]);
        }
      if (options.sourceMap && options.sourceMap.url) {
        code.push("");
        code.push("//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9");
      }
      var result = { code: code.join("\n") };
      if (options.sourceMap)
        result.map = '{"version":3,"sources":[],"names":[],"mappings":""}';
      return result;
    };

    export { $minify as minify };
  }

What the hell is export { $minify as minify }; ?

iRyusa commented 10 months ago

I don’t think it will be easy to migrate from babel to bun sadly. Even if mjml works perfectly fine with bun.On 6 Nov 2023, at 13:14, Alexej Kloos @.***> wrote: Describe the bug Not possible to build via bun. To Reproduce

Create a file:

import mjml2html from "mjml";

/ Compile an mjml string / const htmlOutput = mjml2html( `

Hello World!

`, );

/ Print the responsive HTML generated and MJML errors if any / console.log(htmlOutput);

Build

bun build --sourcemap=external --target=bun ./src/test.ts --outdir ./build && bun run ./build/test.js Expected behavior test.js 3076.02 KB

test.js.map 5568.02 KB

[107ms] bundle 665 modules SyntaxError: Unexpected keyword 'export' at .../api/build/test.js:70860 error: script "testfile" exited with code 1 (SIGHUP)

Line 70860: exports.FILES = [ "......../api/node_modules/uglify-js/tools/exports.js" ]; new Function("domprops", "exports", function() { var code = exports.FILES.map(function(file) { return fs.readFileSync(file, "utf8"); }); code.push("exports.describe_ast = " + describe_ast.toString()); return code.join("\n\n"); }())(require_domprops(), exports); if (+process.env["UGLIFY_BUG_REPORT"]) { var $minify = function(files, options) { if (typeof options == "undefined") options = "<>"; var code = [ "// UGLIFY_BUG_REPORT", to_comment(options) ]; if (typeof files == "string") { code.push(""); code.push("//-------------------------------------------------------------"); code.push("// INPUT CODE", files); } else for (var name in files) { code.push(""); code.push("//-------------------------------------------------------------"); code.push(to_comment(name), files[name]); } if (options.sourceMap && options.sourceMap.url) { code.push(""); code.push("//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9"); } var result = { code: code.join("\n") }; if (options.sourceMap) result.map = '{"version":3,"sources":[],"names":[],"mappings":""}'; return result; };

export { $minify as minify };

} What the hell is export { $minify as minify }; ?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

approached commented 10 months ago

The package uglify-js has follow dependency: mjml > mjml-core > html-minifier > uglify-js

The package https://github.com/kangax/html-minifier would not be maintained. The last version ist from Apr 1, 2019 👎

approached commented 10 months ago

Script flow:

  1. https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L701C22-L701C30
  2. https://github.com/mishoo/UglifyJS/blob/f0ca9cfbe65efc919149e7cd74cedd186d6413ee/lib/minify.js#L73

I think if uglify-js is fixed. Than it will work. I made some test that can be work 👍

approached commented 10 months ago

Ohh last update of https://github.com/mishoo/UglifyJS/ was: Oct 23, 2022