question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Unable to find local modules using resolve alias

See original GitHub issue

Describe the bug

In our project, we are using Vue 3, Typescript, and Vite. In our Vite config and Typescript configuration, we specify the alias to import local modules.

vite.config.js resolve: { alias: { "@": path.resolve(__dirname, "./src"), }, },

tsconfig.json { "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["src/*"] } }, }

It is working as expected when we are running the project using Vite.

In storybook i used this configuration to enable the same custom alias: module.exports = { framework: "@storybook/vue3", stories: ["../src/**/*.stories.@(js|jsx|ts|tsx)"], core: { builder: "@storybook/builder-vite" }, async viteFinal(config, { configType }) { return mergeConfig(config, { resolve: { alias: { "@": path.resolve(__dirname, "../src") }, }, }); }, };

When running Storybook we get this error: “Neither ‘@/mixins/wizardMixin.vue’ nor ‘@/mixins/wizardMixin.js(x)’ or ‘@/mixins/wizardMixin/index.js(x)’ or ‘@/mixins/wizardMixin/index.ts(x)’ could be found in ‘C:/repos/pia-app/frontend/src/views/wizards/travel’”

The actual file is @/mixins/wizardMixin.ts. I tried changing the file name to index.ts, but it is still not resolved.

Expected behavior

I was expecting the resolver to work in builder-vite as it does when running vite.

Screenshots and/or logs

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
augustoodycommented, Aug 16, 2022

For anyone that might be facing this too, in my case, it seemed to be all related to how We use the resolve.alias. After trying another fix from a different thread here (that asked to remove some dependencies from preview.jsx, I found that my alias to @/components that was supposed to parse my app folder was all broken up.

Taking a look at the config coming back from viteFinal, it was setting the root folder as by .storybook folder. To my case just using the resolve.alias like this fixed it:

const path = require('path');

const toPath = (filePath) => path.join(process.cwd(), filePath);

module.exports = {
async viteFinal(config, { configType }) {
    ...,
    return mergeConfig(config, {
      resolve: {
        alias: {
          '@': toPath('app')
        }
      }
    });
  }
};
2reactions
torleifhalsethcommented, Apr 7, 2022

I created a local repo and tried to replicate the issue, but the custom resolver alias is working as expected in this project using the same dependencies and configuration 🤷‍♂️

The only difference is that the original repo has a lot of files with a deeper folder structure, but when trying to replicate this it is also working as expected.

I tried adjusting the blob to define where to retrieve stories from, specifying a single folder with stories that do not reference any of the components using resolver alias. What I notice is that some part of running “npm run storybook” is scanning all files even though the blob is specifying a single folder or file. Do you have any idea why this happens @IanVS and if this might be an issue related to vue-docgen-api https://vue-styleguidist.github.io/docs/Docgen.html#api scanning everything?

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack Alias Module not found - Stack Overflow
My file structure is. Tried different solutions like changing to root to path. resolve(__dirname) and stuff like removing root and adding ...
Read more >
How to fix "resolve.alias" problem in Vite.js - Raul Melo
My package is just a collection of small functions written in TS. From there, I need to parse it to both ES Modules...
Read more >
4. Working with Modules - Perl Hacks [Book] - O'Reilly
Suppose you have a program in your ~/work directory that uses a module named Site::User . By default, Perl will search all of...
Read more >
Autoimports don't use webpack alias if the alias is resolved to ...
So for example if we have a webpack.config.js with such aliases: ... So after that if I resolve LoginForm module from Login module...
Read more >
importlib — The implementation of import — Python 3.11.1 ...
When passed in, target is a module object that the finder may use to make a more ... package were found (i.e. failure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found