oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one

Home Page:https://bun.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dependency resolution does not appear to follow symlink context when in a dockerfile

kevin-lindsay-1 opened this issue · comments

What version of Bun is running?

1.1.8+89d25807f

What platform is your computer?

Linux 6.5.0-28-generic x86_64 x86_64

What steps can reproduce the bug?

  1. Create an example project using bunx create-remix <name>
  2. bun install, bun run build, bun start work as normal
  3. Create a fairly basic dockerfile and attempt to build

Your dockerfile may be slightly simpler than this, but here's the important lines from mine:

FROM oven/bun:1.1.8-alpine
WORKDIR "/usr/root/function"
COPY [\
  "./function/bun.lock*", \
  "./function/package.json*", \
  "./"\
  ]
COPY [ "./function/node_modules/", "./node_modules/" ]
RUN bun install --frozen-lockfile
COPY [ "./function/", "./" ]
RUN bun run build

Using this (default) build script:

// package.json
{
  "scripts":  {
    "build": "remix vite:build"
  }
}

References this binary, which is a symlink:

> readlink -f ./node_modules/.bin/remix
/<omitted for privacy>/node_modules/@remix-run/dev/dist/cli.js

Which contains this line:

// .../node_modules/@remix-run/dev/dist/cli.js
var index = require('./index');

Which produces this error:

 > [build 1/2] RUN bun run build:
#10 0.073 $ remix vite:build
#10 0.086 error: Cannot find module "./index" from "/usr/root/function/node_modules/.bin/remix"
#10 0.086 
#10 0.086 Bun v1.1.8 (Linux x64 baseline)
#10 0.087 error: script "build" exited with code 1

Changing the cli.js file to output directory information results in the symlink's directory being output:

const { cwd } = require('process');
console.log(cwd());
console.log(__dirname);
var index = require('./index');
 > [build 1/2] RUN bun run build:
#16 0.099 $ remix vite:build
#16 0.113 /usr/root/function
#16 0.113 /usr/root/function/node_modules/.bin

This can be worked around by supplying a path to the actual folder being executed from:

// package.json
{
  "scripts":  {
    "build": "./node_modules/@remix-run/dev/dist/cli.js vite:build"
  }
}

What is the expected behavior?

The symlink is followed, the context is set to the symlink's destination directory, and the require succeeds.

What do you see instead?

The symlink is followed, the context is not set to the symlink's destination directory, and the require fails.

Additional information

I imagine you'll want to find out why the symlink doesn't appear to be followed when using a package.json script, because it seems to be working locally in Ubuntu, not sure why it works in one and not others.

I tried this using different dockerhub images, all of them had this problem. Seems like there's something I missed, or this is something specific to docker? I ran this using the built-in docker builder, and I also ran using the kubernetes docker builder. Both had this problem.