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

Cannot find module when import svg #217

Open
ka8725 opened this issue Oct 31, 2020 · 3 comments
Open

Cannot find module when import svg #217

ka8725 opened this issue Oct 31, 2020 · 3 comments

Comments

@ka8725
Copy link

ka8725 commented Oct 31, 2020

My application folders structure is the following:

-src
-public
--images

Svg icons live in public/images folder as per next.js convention.

Webpack config is the following:

module.exports = withFonts(
  withOptimizedImages(
    {
      webpack: (config) => {
        config.resolve.alias['@public'] = path.resolve(__dirname, 'public');
        return config;
      },
    }
  )
);

(imagemin-svgo and svg-sprite-loader are installed).

When I require svg in my src/*.tsx files it works in dev mode, but when I build (run next build) it fails with the following error:

./src/components/Header.tsx:17:16
Type error: Cannot find module 'public/images/ok.svg?sprite'.
> 17 | import Ok from "@public/images/ok.svg?sprite"

What am I doing wrong?

@zhangchinhan
Copy link

I also get this error. When I require svg in my src/*.tsx files it works in dev mode, but when I build (run next build) it fails with the following error:

Cannot find module '../../../public/plus.svg?sprite'.

@JbPons
Copy link

JbPons commented Nov 21, 2020

Did you do specific configuration to use the library on typescript ? It's not work for me even in dev mode

@michielmetcake
Copy link

this should help you out: #103 (comment)

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

No branches or pull requests

4 participants