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

ESM importing CommonJS edge case (breaks vite with vite-plugin-monaco-editor) #3881

Open
skrashevich opened this issue Jul 29, 2023 · 15 comments
Labels
bug Something isn't working

Comments

@skrashevich
Copy link

skrashevich commented Jul 29, 2023

What version of Bun is running?

0.7.1

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

% bun --bun vite dev

What is the expected behavior?

No response

What do you see instead?

% bun --bun vite dev
failed to load config from <cut>/web/vite.config.ts
error when starting dev server:
undefined
error: "vite" exited with code 1 (SIGHUP)

Additional information

vite.config.ts:

/// <reference types="vitest" />
import path from 'path';
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import monacoEditorPlugin from 'vite-plugin-monaco-editor';

// https://vitejs.dev/config/
export default defineConfig({
  define: {
    'import.meta.vitest': 'undefined',
  },
  plugins: [
    preact(),
    monacoEditorPlugin.default({
      customWorkers: [{ label: 'yaml', entry: 'monaco-yaml/yaml.worker' }],
      languageWorkers: ['editorWorkerService'], // we don't use any of the default languages
    }),
  ],
  test: {
    environment: 'jsdom',
    alias: {
      'testing-library': path.resolve(__dirname, './__test__/testing-library.js'),
    },
    setupFiles: ['./__test__/test-setup.ts'],
    includeSource: ['src/**/*.{js,jsx,ts,tsx}'],
    coverage: {
      reporter: ['text-summary', 'text'],
    },
    mockReset: true,
    restoreMocks: true,
    globals: true,
  },
});
@skrashevich skrashevich added the bug Something isn't working label Jul 29, 2023
@Christopher2K
Copy link

Hi, same issue here!
I'm running bun in the official docker image

@trnxdev
Copy link
Contributor

trnxdev commented Jul 30, 2023

could you also provide package.json?

@Christopher2K
Copy link

@TiranexDev Here's mine if that can help

{
  "name": "@project/web",
  "version": "0.0.0",
  "description": "",
  "scripts": {
    "start": "vite",
    "dev": "vite",
    "build": "vite build",
    "serve": "vite preview",
    "typecheck": "tsc --noEmit"
  },
  "license": "MIT",
  "devDependencies": {
    "solid-devtools": "~0.27.6",
    "typescript": "~5.1.6",
    "vite": "~4.3.9",
    "vite-plugin-solid": "~2.7.0"
  },
  "dependencies": {
    "@project/internal": "workspace:*",
    "solid-js": "~1.7.8"
  }
}

Funny thing is that on my machine (Darwin 22.6.0 arm64 arm) it works. Inside the container, it doesn't

@trnxdev
Copy link
Contributor

trnxdev commented Jul 30, 2023

How did you install bun in container?
Also is it a Docker container?
If so then it's not recommended to install bun using curl, https://bun.sh/install lists a tab for Docker

@skrashevich
Copy link
Author

skrashevich commented Jul 30, 2023

How did you install bun in container?

The problem reproduces the same way in both the docker container and macOS

could you also provide package.json?

for example this and this

@skrashevich
Copy link
Author

Funny thing is that on my machine (Darwin 22.6.0 arm64 arm) it works. Inside the container, it doesn't

Have you tried running vite dev inside a same docker container but on arm64 architecture?

@skrashevich
Copy link
Author

replacing monacoEditorPlugin.default({ with monacoEditorPlugin({ fixes this problem in latest canary

@skrashevich
Copy link
Author

skrashevich commented Aug 1, 2023

Upd:

% bun --bun vite dev     

  VITE v4.4.7  ready in 1438 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h to show help
error: "vite" exited with code 11 (SIGSEGV)

Upd2: it start work after execute bun --bun vite optimize

@paperclover
Copy link
Member

This is caused by incorrect handling of ESM importing CommonJS. (the monaco plugin is a common js module)

image

@paperclover
Copy link
Member

i think this is an easy issue. for those looking to contribute, look in Module.ts or ImportMetaObject.ts and see how we handle __esModule, or more specifically how we handle when that isnt used.

@paperclover paperclover added the good first issue Something that would be good for new contributors label Aug 3, 2023
@paperclover paperclover changed the title vite error when starting dev server ESM importing CommonJS edge case (breaks vite with vite-plugin-monaco-editor) Aug 3, 2023
@skrashevich
Copy link
Author

can you suggest any workaround?

@paperclover paperclover removed the good first issue Something that would be good for new contributors label Aug 9, 2023
@Electroid Electroid added the needs repro Needs an example to reproduce label Oct 26, 2023
@aryzing
Copy link

aryzing commented Oct 30, 2023

Seems this issue is still happening. It every so often, when vite performs a hot reload, it crashes with exited with code 11 (SIGSEGV). This is happening with Bun v1.0.7. It fails every 10 - 20 hot reloads.

As a side effect, it messes up the terminal: user input is no longer visible.

Copy link
Contributor

github-actions bot commented Aug 8, 2024

This issue is stale and may be closed due to inactivity. If you're still running into this, please leave a comment.

@github-actions github-actions bot added the stale label Aug 8, 2024
@skrashevich
Copy link
Author

Wait for #9267

@paperclover paperclover removed needs repro Needs an example to reproduce stale labels Aug 10, 2024
@paperclover
Copy link
Member

why was this given the needs repro label? i literally have a repro and explainer given. the issue with this change is it's a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants