Skip to content

.cjs configs from vinext init renames aren't in Vite's default resolve.extensions → extensionless config import fails #13

Description

@hyf0

Problem

After vinext init renames tailwind.config.js/postcss.config.js to .cjs (required under "type": "module"), app code that imports the config extensionlessly fails to resolve, because Vite's default resolve.extensions does not include .cjs.

react.dev's src/components/MDX/Sandpack/Themes.tsx does:

import tailwindConfig from '../../../../tailwind.config';

Build error:

[UNRESOLVED_IMPORT] Could not resolve '../../../../tailwind.config' in Themes.tsx

Workaround used

resolve.extensions: ['.mjs', '.js', '.cjs', '.mts', '.ts', '.jsx', '.tsx', '.json'] (add .cjs). (We later converted the tailwind config to .mjs ESM for a separate reason — importing a .cjs into the bundle is itself awkward: rolldown rejects a .cjs after vite-plugin-commonjs injects export into it.)

Suggested fix

Since vinext init is what renames these configs to .cjs, it should also ensure .cjs resolves (add it to resolve.extensions, or generate an importable ESM config).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions