Closed fargito closed 4 months ago
Unfortunately, I can't use the latest version of register because oxc-resolver
doesn't support Yarn PnP: https://github.com/oxc-project/oxc-resolver/issues/53 . Even a simple import in my setup e.g. import { $ } from 'execa'
will fail:
node:internal/modules/run_main:129
triggerUncaughtException(
^
Error: Cannot find module 'execa': execa cannot be resolved in file:///Users/mitran/Projects/vite-storybook-boilerplate/bin/bootstrap.ts
at resolve (file:///Users/mitran/Projects/vite-storybook-boilerplate/.yarn/unplugged/@swc-node-register-virtual-f17b414b8d/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)
Node.js v20.15.0
Seems like in https://github.com/swc-project/swc/issues/3247#issuecomment-2212345627 , could there be plans to use another resolver?
@psychobolt I'm using pnpm, so maybe it is a separate issue
I have set up a minimal reproduction: https://github.com/fargito/swc-node-relative-import-issue-repro
Thanks @Brooooooklyn! This fixed it for me.
Context
When updating
@swc-node/register
from version1.10.0
to1.10.2
, relative typescript imports are no longer resolved.When using a relative import, I get:
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.