Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use node's resolve system #8

Open
mbrevda opened this issue Dec 16, 2018 · 6 comments
Open

Use node's resolve system #8

mbrevda opened this issue Dec 16, 2018 · 6 comments

Comments

@mbrevda
Copy link

mbrevda commented Dec 16, 2018

It seemed unintuitive that an import would have to point to a relative path and isn't processed by node's module loading system (i.e. check node_modules, etc). Perhaps that because I was expecting the same behavior as webpacks file-loader.

In any case, is that something that can be added?

@idangozlan
Copy link

It should behave the same as the webpack loader. I'm experiencing the same bug.
I will try to push PR for this one asap.

@sheerun
Copy link
Owner

sheerun commented Oct 2, 2019

A way to reproduce issue would be nice

@sheerun
Copy link
Owner

sheerun commented Oct 2, 2019

Please modify example project in this repository so it reproduces this issue

nickpalmer added a commit to nickpalmer/babel-plugin-file-loader that referenced this issue Nov 5, 2020
nickpalmer added a commit to nickpalmer/babel-plugin-file-loader that referenced this issue Nov 6, 2020
@cblanquera
Copy link

@nickpalmer please tell me your commit is found somewhere on npm 👯‍♀️

@sheerun please consider his commit. thanks.

@cblanquera
Copy link

cblanquera commented Sep 26, 2021

If you import an SVG from node_modules let's say from boxicons like this.

import alarm from 'boxicons/svg/regular/bx-alarm.svg';

export default function Hello(props) {
  return (
    <div>
      <img src={alarm} />
    </div>
  );
}

You will get an error like this.

SyntaxError: [file name]: File does not exist

This is because the plugin will look for the file in [CWD]/boxicons/svg/regular/bx-alarm.svg and not in [CWD]/node_modules/boxicons/svg/regular/bx-alarm.svg.

Conventionally, if someone were intending to use an SVG from their project they should use ./folder/something.svg rather than folder/something.svg as this implies that there would be a folder called folder in node_modules.

This is why this commit submitted by @nickpalmer would work.

I looked around for other alternatives and your package is probably the best one to date with the exception for this small quirk. Do let me know if you need further clarifications or if you would like me to submit a working PR.

cblanquera added a commit to Openovate/babel-plugin-file-loader that referenced this issue Sep 26, 2021
cblanquera added a commit to Openovate/babel-plugin-file-loader that referenced this issue Sep 26, 2021
@nsunga
Copy link

nsunga commented Jul 20, 2023

@cblanquera hello! im assuming youre using this babel plugin to server side render the assets created from Webpack's file-loader

if im wrong, no need to answer

but if yes, what version of Webpack and file loader are u running? ideally Wp5 and latest version of file loader is what im looking for

unfortunately, I get the feeling that this package isnt maintained anymore

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants