oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.32k stars 2.78k forks source link

Bun build .js differently locally and in Docker leading to JSX failure #12876

Open laidrivm opened 3 months ago

laidrivm commented 3 months ago

What version of Bun is running?

1.1.21

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

  1. git clone https://github.com/laidrivm/bun-elysia-jsx-blog.git
  2. cd bun-elysia-jsx-blog
  3. mkdir articles
  4. nano articles/index.md
  5. type "#Hello" and save
  6. bun install
  7. bun run build
  8. bun run prod
  9. open localhost:3000 in a browser and see "Hello"
  10. cmd+c
  11. docker build --pull -t blog .
  12. docker run -d -p 3000:3000 blog
  13. open localhost:3000 in a browser and see an error

What is the expected behavior?

Code build locally and in Docker works the same.

What do you see instead?

In Docker there are differences in build lead to JSX failure

Additional information

The code in original generate.tsx, from there everything in Docker's version goes wrong in any JSX used. Let's take for the example:

const fullJsx = (
      <Page title={title} content={contentHtml} includeArrow={true}/>
    );

In Docker version it build to this in generate.js:

var hasAnyProps = function(obj) {
  for (let key in obj)
    return true;
  return false;
};
var mergeDefaultProps = function(props, defaultProps) {
  var result = __create(defaultProps, __descs(props));
  for (let key in defaultProps) {
    if (result[key] !== undefined)
      continue;
    result[key] = defaultProps[key];
  }
  return result;
};
var __create = Object.create;
var __descs = Object.getOwnPropertyDescriptors;
var __merge = (props, defaultProps) => {
  return !hasAnyProps(defaultProps) ? props : !hasAnyProps(props) ? defaultProps : mergeDefaultProps(props, defaultProps);
};
var $$typeof = Symbol.for("react.element");

var ArticleList = ({ links }) => ({
  $$typeof,
  type: "ul",
  key: null,
  ref: null,
  props: {
    children: links.map((link2) => ({
      $$typeof,
      type: "li",
      key: null,
      ref: null,
      props: {
        children: {
          $$typeof,
          type: "a",
          key: null,
          ref: null,
          props: {
            href: link2,
            children: link2
          },
          _owner: null
        }
      },
      _owner: null
    }))
  },
  _owner: null
});

Then console.log(fullJsx) prints <NoName ... />and renderToString(fullJSX) returns nothing instead of rendered html.

While in locally built generate.js it converts to:

var ArticleList = ({ links }) => u3("ul", {
  children: links.map((link2) => u3("li", {
    children: u3("a", {
      href: link2,
      children: link2
    }, undefined, false, undefined, this)
  }, undefined, false, undefined, this))
}, undefined, false, undefined, this);

and everything goes smoothly.

Both local and Docker bun --version are 1.1.21.

I've also checked the differences between local and Docker node_modules/, but they're only in dev dependencies, which is as expected.

laidrivm commented 3 months ago

I believe there's something with base oven/bun Docker image, that's why I'm opening this issue.