Skip to content

Runtime helpers resolve from the user's file, so a global oxnode fails with ERR_MODULE_NOT_FOUND #794

Closed
voidzero-dev/vite-plus
#2936

Description

@fengmk2

Lowered syntax imports runtime helpers from @oxc-node/core/helpers/*, and that bare specifier is resolved relative to the transformed file. It only works when @oxc-node/core is installed where that file can see it, so a global oxnode (the @oxc-node/cli README suggests "Install globally, you can use it replace node command anywhere") fails on the first class field.

Reproduction

npm install -g @oxc-node/[email protected], then in an empty directory:

// main.ts
class Counter {
  count = 1;
}
console.log(new Counter().count);
$ oxnode main.ts
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@oxc-node/core' imported from /private/tmp/repro/main.ts

node main.ts prints 1. The same happens with node --import @oxc-node/core/register for a script outside the project that has @oxc-node/core installed.

The transformed code:

"use strict";
var _defineProperty = require("@oxc-node/core/helpers/defineProperty");
class Counter {
	constructor() {
		_defineProperty(this, "count", 1);
	}
}

Environment: @oxc-node/cli / @oxc-node/core 0.1.4, Node.js 22.18.0, 24.21.0, and 26.5.0, macOS arm64.

Cause

HelperLoaderOptions { module_name: "@oxc-node/core", .. } (src/lib.rs#L741-L742) emits bare specifiers, and neither the resolve hook nor the pirates hook resolves them from @oxc-node/core itself.

Suggested fix

  • Resolve @oxc-node/core/helpers/* from the loader's own location: in the resolve hook with nextResolve(specifier, { ...context, parentURL: import.meta.url }), and in the CommonJS output with a require created for the loader's location instead of the file's.
  • Related: class fields, private members, and static blocks run natively on every supported Node.js, and using is native from Node.js 24, but they are always lowered (class_properties: Some(..), class_static_block: true, explicit_resource_management: true, L727-L737). Lowering them only when the semantics require it (useDefineForClassFields: false, legacy decorators) or the running Node.js lacks them would remove most helper imports, and keep stack traces and Function.prototype.toString() closer to the source.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions