Skip to content

Register: unable to resolve relative import with oxc-resolver #804

Description

@fargito

Context

When updating @swc-node/register from version 1.10.0 to 1.10.2, relative typescript imports are no longer resolved.

When using a relative import, I get:

node:internal/modules/run_main:129
    triggerUncaughtException(
    ^
Error: Cannot find module './shared': ./shared cannot be resolved in file:///home/runner/work/rust-cdk-serverless/rust-cdk-serverless/iac/index.ts
    at resolve (file:///home/runner/work/rust-cdk-serverless/rust-cdk-serverless/node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected]/node_modules/@swc-node/register/esm/esm.mjs:208:15)
    at async nextResolve (node:internal/modules/esm/hooks:866:22)
    at async Hooks.resolve (node:internal/modules/esm/hooks:304:24)
    at async handleMessage (node:internal/modules/esm/worker:196:18)

Investigation

The issue has probably been introduced by #798, more precisely here.

I'm a bit puzzled, because the call to resolver.async is done with the correct arguments according to the oxc-resolver docs:

  • directory must be an absolute path to a directory where the specifier is resolved against. For CommonJS modules, it is the __dirname variable that contains the absolute path to the folder containing current module. For ECMAScript modules, it is the value of import.meta.url. In my case, it gives the expected value, i.e. /home/runner/work/rust-cdk-serverless/rust-cdk-serverless/iac
  • identifier: in my case it is ./shared

This looks correct according to the oxc-resolver docs, but oxc-resolver cannot find it. Maybe the ts config is incorrectly passed to the resolver?

I will try and set up a minimal reproduction in the coming days.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions