Skip to content

✨ Vite 7 Support #320

@pcfreak30

Description

@pcfreak30

Describe the bug

error during build:
Build failed with 1 error:

[plugin vite:oxc-transpile]
Error: `await` is only allowed within async functions and at the top levels of modules
11 |            requiredVersion: "18"
12 |    } } }));
13 |    const exportModule = await res.then((factory) => factory());
   |                        ^^^^^
14 |    module.exports = exportModule;
15 |  });
    at transformWithOxc

This is connected to

export function writeLoadShareModule(pkg: string, shareItem: ShareItem, command: string) {

I have tried to debug further but vite 7 is making it extremely hard to breakpoint and debug inside the plugin. So it is unclear if I will be able to get a solution if I can't do so.

I am unsure also what has changed. The info I was able to extract though is the following from the vite-vite/vite-host example app:

import { __commonJSMin } from "./chunk-!~{004}~.js";
import { require_index_cjs, require_viteViteHost__mf_v__runtimeInit__mf_v__ } from "./viteViteHost__mf_v__runtimeInit__mf_v__-!~{008}~.js";

//#region node_modules/__mf__virtual/viteViteHost__loadShare__react__loadShare__.js
var require_viteViteHost__loadShare__react__loadShare__ = __commonJSMin((exports, module) => {
	const { loadShare } = require_index_cjs();
	const { initPromise } = require_viteViteHost__mf_v__runtimeInit__mf_v__();
	const res = initPromise.then((_) => loadShare("react", { customShareInfo: { shareConfig: {
		singleton: false,
		strictVersion: false,
		requiredVersion: "18"
	} } }));
	const exportModule = await res.then((factory) => factory());
	module.exports = exportModule;
});

//#endregion
export { require_viteViteHost__loadShare__react__loadShare__ };

What stands out is the __commonJSMin wrapper being used which is a core entity/mechanism in rolldown https://github.com/rolldown/rolldown/blob/9c158fe6aa9296b0da53ec044dcfa78014e0f629/crates/rolldown/src/runtime/index.js#L22 . Unclear why its getting done like this, but the current approach has some clear issues with v7.

Version

7.0.10

Reproduction

n/a

Relevant log output

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    COMMUNITY: PR is welcomedWe think it's a good feature to have but would love for the community to help with the PR for itenhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions