Skip to content

ERR_MODULE_NOT_FOUND (with TypeScript import path aliases?) #452

Closed

Description

@mtmacdonald

Hello.

I have a Typescript Express app using pnpm workspaces and some import aliases (under compilerOptions.path in tsconfig.json), like this:

{
    "compilerOptions": {
        "paths": {
            "common/*": ["./common/*"],
            "server/*": ["./server/*"],
            "client/*": ["./client/*"],
        },
  }
}

Today, I use tsx, and invoke my "development mode" server like this:

"server": "tsx watch ./server/server.ts",

I've tried to do the same using oxc-node

"server": "node --import @oxc-node/core/register ./server/server.ts",

But I get import errors like:

node:internal/modules/run_main:123
    triggerUncaughtException(
    ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'common' imported from <repo_path>/common/enums/feature-enums.ts
Did you mean to import "<file:///<repo_path>/common/Internationalisation/translation-map.json"?
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:266:9)
    at packageResolve (node:internal/modules/esm/resolve:767:81)
    at moduleResolve (node:internal/modules/esm/resolve:853:18)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at resolve (file:///<repo_path>/node_modules/.pnpm/@[email protected]/node_modules/@oxc-node/core/esm.mjs:16:10)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
    at handleMessage (node:internal/modules/esm/worker:199:24)
    at Immediate.checkForMessages [as _onImmediate] (node:internal/modules/esm/worker:141:28) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v22.19.0
[nules/run_main:123](node:internal/modules/run_main:123)
    triggerUncaughtException(
    ^
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'common' imported from  <repo_path>/server/rootroutes/rootroutes.ts
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:266:9)
    at packageResolve (node:internal/modules/esm/resolve:767:81)
    at moduleResolve (node:internal/modules/esm/resolve:853:18)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at resolve (file:///<repo_path>/node_modules/.pnpm/@[email protected]/node_modules/@oxc-node/core/esm.mjs:16:10)
    at nextResolve (node:internal/modules/esm/hooks:748:28)
    at Hooks.resolve (node:internal/modules/esm/hooks:240:30)
    at handleMessage (node:internal/modules/esm/worker:199:24)
    at Immediate.checkForMessages (node:internal/modules/esm/worker:141:28) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v22.19.0

Any pointers / tips? I wondered if it's a config issue (like oxc-node not detecting my tsconfig.json). If you need a "minimal reproduction" example, I can try to make one.

Thank you again for the great tool!

Activity

  1. Brooooooklyn commented on Sep 12, 2026

    @Brooooooklyn
    SponsorMember

    Thanks for the report — and sorry this sat so long. I dug into the whole scenario space against current main; here is where things stand.

    The alias resolution itself is fixed on main (not yet in a published release — the last tag, v0.1.0, predates it):

    I verified both with a fixture matching your layout: root tsconfig.json with paths, server/server.ts importing common/enums/feature-enums, run via node --import @oxc-node/core/register ./server/server.ts.

    One thing to check in your repo: each directory that contains importing files needs to be claimed by the tsconfig that declares the paths — the same ownership rule tsc applies. If server/ has its own tsconfig.json that neither declares paths nor says "extends": "../tsconfig.json", the aliases won't resolve there. That is deliberate TypeScript parity, not a bug.

    While probing I found a second bug in your command shape — a CommonJS-typed project (no "type": "module") couldn't run a .ts entry with import syntax at all (ERR_REQUIRE_CYCLE_MODULE), and named imports from such files lost their exports. That's fixed in #759.

    So: the next release containing #569, #745 and #759 should run your setup as-is. I'd leave this open until the release is out, but if you can try a build from main in the meantime, we'd love to hear whether it covers your workspace.

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