remix: Importing PNG/SVG from node_modules failing

What version of Remix are you using?

1.1.3

Steps to Reproduce

  1. Install uswds NPM module
  2. In app/routes/index.tsx, import an image with import img from 'uswds/img/circle-124.png' and put on the page with <img src={img} alt="" />
  3. Run dev server npm run dev and load up the page.

Expected Behavior

Circle image should be displayed

Actual Behavior

I get the following error:

C:\Users\jkjustjoshing\Documents\myrepo\node_modules\uswds\dist\img\circle-124.png:1
�PNG


SyntaxError: Invalid or unexpected token
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\jkjustjoshing\Documents\myrepo\build\index.js:446:36)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Fixed by #6813

I guess that’s why my current workaround works:

import svgPath from "~/../node_modules/path/to/svg.svg";