Skip to content

Incorrect mapping resolution: an absolute to a relative path without the baseUrl parameter #18

Open
@unennhexium

Description

@unennhexium

Minimal repo to reproduce this issue

Project Structure

/
└── project
    ├── custom
    │   └── index.ts
    ├── main.ts
    ├── package.json //  `rollup --config` as `build` script
    ├── tsconfig.json
    └── rollup.config.js

Code Snippets

// ./custom/index.ts
export default function() { return 'hello world' }
// ./main.ts
export { default as func } from 'custom'
// ./tsconfig.json
{
  "compilerOptions": {
    // "baseUrl": "./", // [1]
    "paths": { "custom": [ "./custom/index.ts" ] }
  }
}
// ./rollup.config.js
export default {
  input: './main.ts',
  output: { dir: './dist' },
  plugins: [
      typescriptPaths({ 
        // absolute: false, // [2]
        preserveExtensions: true,
      }),
      esbuild(),
  ],
}

Error Messages

[1] [2]

[!] Error: Could not load /project/project/custom/index.ts (imported by main.ts):

  • ENOENT: no such file or directory, open 'project/project/custom/index.ts'

Explanation: Duplicated project root

[1] [2] absolute: false in plugin configuration

[!] Error: Could not load project/custom/index.ts (imported by main.ts):

  • ENOENT: no such file or directory, open 'project/custom/index.ts'

Explanation: Missing leading slash

✅ [1] [2] "baseUrl": "./" in typescirpt configuration

No erros, output file:

// ./dist/main.js
function index() { return "hello world"; }
export { index as func };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions