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

Can't import node_module SVG #9248

Open
GuenyooBaywa opened this issue Apr 17, 2024 · 2 comments
Open

Can't import node_module SVG #9248

GuenyooBaywa opened this issue Apr 17, 2024 · 2 comments

Comments

@GuenyooBaywa
Copy link

Reproduction

Found an issue that was closed: #8606
No further help was commented on however and the help section on the Remix Docs didn't help either.

Comment from other Issue:

@pcattori I seem to have the same problem and the troubleshooting section didn't help.

I've a similar setup:

I have a package, which expects "@package/icons" to exist in the repository and in that packages lib build, it imports it:

import icons from "@package/icons/lib/icons/icons.symbols.svg";

In my Library, everything works fine.

In Remix, when I start my dev or build, I get the error:
"[vite] Internal server error: Unknown file extension ".svg"

In my vite.config.ts I have an alias:

'@package/icons': resolve(__dirname, './node_modules/@package/icons'),

I've tried using the cjsInterop Package (however, I'm trying to reference a node_module svg here, not a JS File).

When I try to incorporate @brophdawg11 's suggestion with ssr.noExternal, I also get the error:
[vite] Internal server error: module is not defined

So I'm currently at an impasse and can confirm that I, too, have the same problem importing non-JS-Files from external packages.

System Info

System:
    OS: macOS 14.4.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 253.22 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  Browsers:
    Chrome: 124.0.6367.62
    Edge: 123.0.2420.97
    Safari: 17.4.1
  npmPackages:
    @remix-run/dev: ^2.8.1 => 2.8.1 
    @remix-run/node: ^2.8.1 => 2.8.1 
    @remix-run/react: ^2.8.1 => 2.8.1 
    @remix-run/serve: ^2.8.1 => 2.8.1 
    vite: ^5.2.8 => 5.2.9

Used Package Manager

npm

Expected Behavior

Third-party SVGs should be able to be impored

Actual Behavior

Third-party (node_module package) SVGs can't be imported

@brophdawg11
Copy link
Contributor

Could you provide a minimal reproduction?

@brophdawg11 brophdawg11 added needs-response We need a response from the original author about this issue/PR package:dev vite labels Apr 18, 2024
@GuenyooBaywa
Copy link
Author

GuenyooBaywa commented Apr 18, 2024

@brophdawg11 in the original issue #8606 there is a stackblitz link:
https://stackblitz.com/edit/vitejs-vite-u1xsya

I've also noticed that if I link the package, everything works fine. Only when I install the package it fails. If that helps.

I've visualized the dependencies for clarity:

image

@github-actions github-actions bot removed the needs-response We need a response from the original author about this issue/PR label Apr 18, 2024
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

2 participants