Skip to content

typescript paths alias #1935

@yannbcf

Description

@yannbcf

Describe the bug

I try to get the typescript path aliases to work since it should be working right now on the 1.2.65 swc core version, am i doing something wrong ?

TypeError [ERR_INVALID_MODULE_SPECIFIER]: Invalid module "@api" is not a valid package name imported from C:\Users\x\test\hello.js
    at packageResolve (internal/modules/esm/resolve.js:601:11)
    at moduleResolve (internal/modules/esm/resolve.js:691:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:805:11)
    at Loader.resolve (internal/modules/esm/loader.js:88:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:241:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:72:40)
    at link (internal/modules/esm/module_job.js:71:36) {
  code: 'ERR_INVALID_MODULE_SPECIFIER'
}

Input code

api.ts

export const api = 0;

hello.ts

import { api } from '@api';
console.log('api', api);

Tsconfig

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "@api": ["src/api"]
        }
    }
}

Config

{
    "jsc": {
      "parser": {
        "syntax": "typescript",
        "dynamicImport": true
      },
      "target": "es2016",
      "paths": {
        "@api": ["src/api"]
      }
    },
    "minify": false
}

Expected behavior
It should replace the alias with a relative path

Version
1.2.65

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions