79171421

Date: 2024-11-08 20:12:55
Score: 1.5
Natty:
Report link

Thanks to @Alex Craft answer: https://stackoverflow.com/a/78658715/3266845 please vote him up instead.

I noticed:

So I tried:

It could very well be me missing something, but I spent some hours trying different things and observing how imports resolve but could not make sense of it. I think the issue is occurring somewhere between my (a) monorepo setup (b) root tsconfig and package tsconfig extends (c) rootDir baseUrl incorrectly set up? (d) storybook-vite (?)

I think @Alex Craft is the most reasonable answer and it almost worked for me. I had to make some changes, shown below.

import { parse } from 'jsonc-parser';

export default defineConfig({
  ...
  resolve: {
    alias: getPathsFromTsConfig()
  },
  ...
});

function getPathsFromTsConfig() {
  const tsconfig = parse(fs.readFileSync('./tsconfig.json', 'utf-8'));
  const aliases = {};
  for (const [key, value] of Object.entries(tsconfig.compilerOptions.paths)) {
    const cleanKey = key.replace('/*', '');
    const cleanValue = value[0].replace('/*', '');
    const resolvedPath = path.resolve(__dirname, cleanValue);
    aliases[cleanKey] = resolvedPath;
  }
  return aliases;
}
Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Blacklisted phrase (1): did not work
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-1): worked for me
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • User mentioned (1): @Alex
  • User mentioned (0): @Alex
Posted by: Kerry Johnson