Skip to content

fix(vite): pre-bundle CJS dependencies#104

Open
ericelliott wants to merge 1 commit intozachwinter:masterfrom
ericelliott:fix/vite-cjs-deps
Open

fix(vite): pre-bundle CJS dependencies#104
ericelliott wants to merge 1 commit intozachwinter:masterfrom
ericelliott:fix/vite-cjs-deps

Conversation

@ericelliott
Copy link
Copy Markdown

  • Filter out non-existent 'phone' dependency
  • Add socket.io-client and music-metadata to optimizeDeps
  • Resolves ESM/CJS module resolution errors

- Filter out non-existent 'phone' dependency

- Add socket.io-client and music-metadata to optimizeDeps

- Resolves ESM/CJS module resolution errors
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @ericelliott, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the Vite configuration to resolve module resolution issues, particularly those arising from CommonJS dependencies. By explicitly including socket.io-client and music-metadata for pre-bundling and removing a non-existent dependency, the changes ensure better compatibility and a more stable build process when dealing with mixed module formats.

Highlights

  • Dependency Optimization: The Vite configuration now filters out a non-existent 'phone' dependency from the optimizeDeps.include list, cleaning up the build process.
  • CJS Dependency Pre-bundling: socket.io-client and music-metadata have been explicitly added to Vite's optimizeDeps.include to ensure they are pre-bundled and converted to ESM, resolving potential module resolution errors.
  • Module Resolution Fixes: These changes collectively address and resolve existing ESM/CJS module resolution errors within the Vite build, improving compatibility and stability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Vite configuration to pre-bundle CJS dependencies, resolving module resolution errors. It correctly filters out a non-existent 'phone' dependency and adds 'socket.io-client' and 'music-metadata' to optimizeDeps. My review includes two main points: first, a high-severity issue regarding the music-metadata package which is included for optimization but is missing from package.json. Second, a medium-severity suggestion to improve code readability by refactoring the dependency array construction.

Comment thread vite.config.ts
"dayjs/locale/en",
"dayjs/esm/locale/en",
"socket.io-client",
"music-metadata"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The music-metadata package is being added to optimizeDeps.include but is not declared as a project dependency in package.json. This can lead to build failures in clean environments or unpredictable behavior if a transitive dependency version changes. To ensure a stable and predictable build, please add music-metadata to the dependencies in package.json.

Comment thread vite.config.ts
Comment on lines 13 to 28
// Fix dayjs ES module issue from AppKit - merge configs properly
// Pre-bundle packages with CommonJS dependencies so Vite converts them to ESM
return {
...baseConfig,
optimizeDeps: {
...baseConfig.optimizeDeps,
include: [...(baseConfig.optimizeDeps?.include || []), "dayjs", "dayjs/locale/en", "dayjs/esm/locale/en"]
include: [
...(baseConfig.optimizeDeps?.include || []).filter(dep => dep !== 'phone'),
"dayjs",
"dayjs/locale/en",
"dayjs/esm/locale/en",
"socket.io-client",
"music-metadata"
]
}
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and to avoid a long inline expression, you could extract the logic for filtering base dependencies into a constant. This makes the include array's composition clearer.

  // Fix dayjs ES module issue from AppKit - merge configs properly
  // Pre-bundle packages with CommonJS dependencies so Vite converts them to ESM
  const baseIncludes = (baseConfig.optimizeDeps?.include || []).filter(
    (dep) => dep !== "phone"
  );

  return {
    ...baseConfig,
    optimizeDeps: {
      ...baseConfig.optimizeDeps,
      include: [
        ...baseIncludes,
        "dayjs",
        "dayjs/locale/en",
        "dayjs/esm/locale/en",
        "socket.io-client",
        "music-metadata"
      ]
    }
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant