-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Unable to find local modules using resolve alias #316
Comments
@thalseth would you be willing to make a reproduction of this, so we can look into it? Another thing you can try is creating the new config using mergeConfig, and then logging out the result before returning it, in case it's not what you're expecting. |
Thanks for the immediate response @IanVS! If you look at the screenshot I posted it looks like the resolver is trying to find the module in the context of the file importing it :( I am experiencing the same issue using the mergeConfig function. Here is the code and result when logging. It looks like the resolve alias is defined as expected.
|
Hmmmm, yeah sorry, without a repo that I can poke around with, I'm not sure how much help I can be here, unfortunately. |
I tried creating a repo to poke around with here https://stackblitz.com/edit/vitejs-vite-dg7twk @IanVS, but for some reason, storybook is not running as expected 🤷♂️ |
Sometimes it's easier to just create a repository with |
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? |
Yes, vue-docgen needs to scan all of your vue components so that it can gather docs information to show in the args table and docsPage.
Is that causing problems for you, or just unexpected? |
Ok, maybe vue-docgen does not like some of the Vue APIs we are using? We are using both Vue 2 and Vue 3 APIs 🤔 When removing the imports mentioned above I don't get any error on other named alias imports. The imports are used as Vue mixins and that might be a feature vue-docgen does not support, or maybe the content of the mixins is unsupported. Now it just states: "The passed source is empty". |
And this is still not something you're able to reproduce in a fresh repository? If you can, I'll try to help take a look. |
No, not able to reproduce this. I just tested to add a mixin in my fresh repository, but it is working as expected there. The test mixin is simplified but I guess this shows that using mixins is not the problem. |
Woop, I just caught the same warning output in the reproduced repository using mixins now. I did not see it immediately because the storybook was showing all components as expected. I will create the reproduction and post it when available on Github. For some reason, I am not able to push directly to Github from this enterprise computer 🙈 Thanks for hanging in there @IanVS 🍻 |
It seems like vue-docgen-api might not have full vue3 compatibility: vue-styleguidist/vue-styleguidist#997 (comment), and I also found vue-styleguidist/vue-styleguidist#1191 which might be related. Overall though, this does seem like it's probably a vue-docgen-api issue, doesn't it? I also found vue-styleguidist/vue-styleguidist#359 (comment) which could help, maybe. |
That said, it shouldn't error out, and so I think that's a bug we need to fix here. Your reproduction will help a lot with that, if/when you're able to push it up. |
Sorry it took so long: https://github.com/thalseth/vite-project I will look at the issues you posted now. |
@torleifhalseth, sorry it took so long to get back to this, but I pulled down your repo and tried to run it, but it's missing a storybook config file ( |
Hey guys, any updates on this? I am trying to deal with this bug in a private repo (migrating from webpack builder) but have no idea of what to try next... |
@rafael-telles if you can provide a reproduction, I can try taking a look. The one provided by @torleifhalseth was incomplete. |
For anyone that might be facing this too, in my case, it seemed to be all related to how We use the Taking a look at the 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')
}
}
});
}
}; |
Thanks @augustoody |
I was not having luck with vue-docgen picking up my aliases. I may be doing something wrong in my config, and I am stuck on older versions of some libraries. I created a patch in the meantime. My temporary hack is not working with I thought I would share it in case it is useful for somebody, or in case there is an actual bug still. The file I was trying to import was controller.ts. The error messages I was getting were:
I made some changes to the function vueDocgen(vueVersion) {
// Patch - Use the aliases from the vite config. Var defined to store config.
let config;
return {
name: 'vue-docgen',
// Patch - Set config var.
configResolved(resolvedConfig) {
config = resolvedConfig
},
async transform(src, id) {
// Patch - Shape resolvedConfig alias back into object format.
const aliasArray = config.resolve.alias;
const alias = aliasArray.reduce((aliasObj, value) => {
const { find, replacement } = value;
if (find && replacement) {
aliasObj[find] = replacement;
}
return aliasObj;
}, {});
if (/\.vue$/.test(id) && !/\.stories\.vue$/.test(id)) {
// Patch - `alias` in the object format can be passed as 2nd arg
// to vue-docgen-api.parse
const metaData = await (0, vue_docgen_api_1.parse)(id, alias);
const metaSource = JSON.stringify(metaData);
const s = new magic_string_1.default(src);
const componentLocation = vueVersion === 3 ? '_sfc_main' : '__component__.exports';
s.append(`;${componentLocation}.__docgenInfo = ${metaSource}`);
return {
code: s.toString(),
map: s.generateMap({ hires: true, source: id }),
};
}
},
};
} Storybook - 6.5.16 |
I know this is closed and you need a reproduction case, but just adding a data point that this is biting me too. It seems related to storybookjs/storybook#9695 since the only thing throwing these warnings are files in |
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
The text was updated successfully, but these errors were encountered: