Skip to content
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

Error when trying to resolve alias '/@/' #759

Closed
LoveofRedMoon opened this issue Jan 4, 2021 · 3 comments
Closed

Error when trying to resolve alias '/@/' #759

LoveofRedMoon opened this issue Jan 4, 2021 · 3 comments

Comments

@LoveofRedMoon
Copy link

Expected Behavior

file /output/bundle.js needs required('src/index');

Actual Behavior

file /output/bundle.js shows require('../../../@/index');

Additional Information

In alias plugin, the following code will return false when pass paramters ('/@/', '/@/vue/Button.vue')

function matches(pattern: string | RegExp, importee: string) {
  if (pattern instanceof RegExp) {
    return pattern.test(importee);
  }
  if (importee.length < pattern.length) {
    return false;
  }
  if (importee === pattern) {
    return true;
  }
  const importeeStartsWithKey = importee.indexOf(pattern) === 0;
  const importeeHasSlashAfterKey = importee.substring(pattern.length)[0] === '/';
  return importeeStartsWithKey && importeeHasSlashAfterKey;
}

I guess it is necessary to remove the trailing slash with pattern

for example:

function getEntries({ entries }: RollupAliasOptions): readonly Alias[] {
  if (!entries) {
    return [];
  }

  if (Array.isArray(entries)) {
    return entries;
  }

  return Object.entries(entries).map(([key, value]) => {
    // return { find: key, replacement: value };
    return { find: key.replace?.(/\/+$/, '') , replacement: value };
  });
}
@shellscape
Copy link
Collaborator

@LoveofRedMoon does your issue contains a workaround or if that is a proposed fix for the plugin?

@Olyno
Copy link

Olyno commented Feb 27, 2021

Hi, I got a problem with a Vuejs 2 project too using the alias plugin. I think @LoveofRedMoon suggested to replace all slash using return { find: key.replace?.(/\/+$/, '') , replacement: value }; instead of the current way to fix this problem.

@stale stale bot added the x⁷ ⋅ stale label Apr 29, 2021
@stale
Copy link

stale bot commented Apr 30, 2021

Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants