dividab / tsconfig-paths

Load node modules according to tsconfig paths, in run-time or via API.
MIT License
1.82k stars 104 forks source link

loadConfig errors if paths property is missing #191

Open EarthlingDavey opened 2 years ago

EarthlingDavey commented 2 years ago

const { absoluteBaseUrl, paths } = tsConfigPaths.loadConfig();

Results in:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Object.getAbsoluteMappingEntries (/app/node_modules/tsconfig-paths/lib/mapping-entry.js:17:49)
    at Module.createMatchPath (/app/node_modules/tsconfig-paths/lib/match-path-sync.js:18:38)
    at file:///app/loader.js:9:29
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async initializeLoader (node:internal/process/esm_loader:74:19)
    at async loadESM (node:internal/process/esm_loader:87:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)
alalonde commented 2 years ago

I ran into this too; a simple workaround is to specify paths: {}, such as:

tsConfigPaths.register({
  baseUrl: 'dist',
  paths: {},
});