oven-sh / bun

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

`delete` operator not working as excepted #6747

Open lnoss opened 1 year ago

lnoss commented 1 year ago

What version of Bun is running?

1.0.7

What platform is your computer?

Linux 5.15.90.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

  1. Initialize a Nuxt app: bun x nuxi init my-nuxt-app
  2. Integrate NuxtUI bun add @nuxt/ui (the module also installs @nuxtjs/tailwindcss and @nuxtjs/color-mode)
  3. In nuxt.config.ts at root project level, add:
    export default defineNuxtConfig({
    modules: ['@nuxt/ui']
    })
  4. Start the dev server with Bun runtime (bun --bun run dev) and compare it with Node runtime (bun run dev)

What is the expected behavior?

$ nuxt dev
Nuxt 3.8.0 with Nitro 2.7.1

  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

ℹ Using default Tailwind CSS file
  ➜ DevTools: press Shift + Alt + D in the browser (v1.0.0)

ℹ Tailwind Viewer: http:/localhost:3000/_tailwind/
ℹ Vite client warmed up in 3230ms
✔ Nitro built in 658 ms

What do you see instead?

$ nuxt dev
Nuxt 3.8.0 with Nitro 2.7.1

  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

 WARN

 WARN  warn - As of Tailwind CSS v2.2, lightBlue has been renamed to sky. 

 WARN  warn - Update your configuration file to silence this warning.

 WARN

 WARN  warn - As of Tailwind CSS v3.0, warmGray has been renamed to stone.

 WARN  warn - Update your configuration file to silence this warning.

 WARN

 WARN  warn - As of Tailwind CSS v3.0, trueGray has been renamed to neutral.

 WARN  warn - Update your configuration file to silence this warning.

 WARN

 WARN  warn - As of Tailwind CSS v3.0, coolGray has been renamed to gray.

 WARN  warn - Update your configuration file to silence this warning.

 WARN

 WARN  warn - As of Tailwind CSS v3.0, blueGray has been renamed to slate.

 WARN  warn - Update your configuration file to silence this warning.

ℹ Using default Tailwind CSS file
  ➜ DevTools: press Shift + Alt + D in the browser (v1.0.0)

ℹ Tailwind Viewer: http:/localhost:3000/_tailwind/
✔ Nitro built in 451 ms
ℹ Vite client warmed up in 3413ms

Additional information

See original post by @Daynil in https://github.com/tailwindlabs/tailwindcss/issues/4690#issuecomment-1046087220

Tailwind has deprecated several color names and renamed them, but has left the deprecated names in the colors object for backwards compatibility. These deprecated colors will presumably be removed in a future version, at which point the warning will not show up.

In the meantime, if you need to spread the full default color object into your theme.colors and want to suppress the warning, just delete the deprecated colors after importing.

NuxtUI delete these references and the solution works with Node, but not with Bun. Lines concerned: https://github.com/nuxt/ui/blob/4ce23746da27ad0ef9b1833e41105165045f1cb8/src/module.ts#L13#L17

I thought it was a problem of weak/strong references or more generally with garbage collector implementation, but @Jarred-Sumner thinks that the root cause is something linked to some property set to readonly and delete is not throwing an error maybe due to some sloppy mode thing. Or something is marked as enumerable (& vice versa).

Fixing this issue should close nuxt/ui#809.

thunfisch987 commented 1 year ago

i'm not sure if this could lead to more serious bugs than this, but it should still be looked into

thunfisch987 commented 1 year ago

any updates on this?

pi0 commented 9 months ago

Please see the workaround here: https://github.com/nuxt/ui/issues/809#issuecomment-1921810965

// https://github.com/oven-sh/bun/issues/6747
import { createRequire } from 'node:module'
const _require = createRequire(import.meta.url)
const defaultColors = _require('tailwindcss/colors.js')
delete defaultColors.lightBlue
delete defaultColors.warmGray
delete defaultColors.trueGray
delete defaultColors.coolGray
delete defaultColors.blueGray

I tried to make a more minimal reproduction but it seems it can only happen in complex mixed CJS/ESM scenarios. (due to how it is an edge-case, probably would make sense we fix it in nuxt/ui workaround unless there are more reports without nuxt or nuxt/ui...)

wottpal commented 1 month ago

any updates? seems to be the only remaining thing that behaves weirdly after going all-in on bun

simaotwx commented 4 days ago

Weirdly, I don't get this on my host (Bun 1.1.34, Arch Linux), but I do get it in the docker image oven/bun (also 1.1.34)