tsc-alias: Urgent help needed - Failed to import `replacer` file

Hi there,

I’ve been trying to use this package successfully but I can’t import the replacer file.

Here is my file structure

mono-repo
- packages
- - project
- - - src
- - - - assets
- - - - component
- - - - - Button
- - pathReplacer.js
- - tsconfig.json
tsconfig.json

In the Button file, I use an alias for the path like require('#/assets/images/button.png')

Here is my project tsconfig.json

{
  "extends": "../../tsconfig.json",
  "include": ["**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules", "dist"],
  "compilerOptions": {
    "skipLibCheck": true,
    "emitDecoratorMetadata": true,
    "outDir": "dist",
    "isolatedModules": true,
    "declarationDir": "dist",
    "typeRoots": ["./src/types/types.d.ts", "./src/types/styled.d.ts", "../../node_modules/@types"],
    "paths": {
      "#*": ["./src/*"]
    }
  },
  "references": [
    {
      "path": "../ui-core"
    }
  ],
  "tsc-alias": {
    "verbose": false,
    "resolveFullPaths": true,
    "replacers": {
      "pathReplacer": {
        "enabled": true,
        "file": "./pathReplacer.js"
      }
    }
  }
}

I can build the project fine with tsc without errors but as soon I add the tsc-alias section in the tsconfig.json file I get this error

tsc-alias error: Failed to import replacer "./pathReplacer.js"

Here the content of pathReplacer.js

import { replaceTscAliasPaths } from 'tsc-alias'

replaceTscAliasPaths()

Can you help me to resolve this problem?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Awesome.

Thank you so much for your help.

I only looked at the https://github.com/justkey007/tsc-alias#usage section and thought I have to write the replacer like that.

WELL DONE !!!