Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
NextJS error importing component with local image from other package

I have a monorepo that has a NextJS project and a React library. I want to import components from the react project to the nextjs project. So far so good... but when I try to import a component that has a local image in it I get the following error:

Automatic publicPath is not supported in this browser

I understand that I have to put the path of the assets in the webpack config file, but even doing that NextJS can't resolve the images. What am i missing?

I've replicated the error in an public repository so you could see what's happening.

Component library:

import React from "react";

const TestComponent = () => (
  <div>
    <p>Test Component</p>
    <img src={require("./arrow-down.png").default} width="10px" height="10px" />
  </div>
);

export default TestComponent;

NextJS importing the component:

import TestComponent from "react-project";

export default function Home() {
  return (
    <div>
      <TestComponent />
    </div>
  );
}

The project has the following structure -- packages -- nextjs-project -- react-project -- package.json

public repository.

You only need to install the dependencies with yarn (or npm if you like) and build the react library with webpack (yarn build).

I know im missing some theory about images in NextJS. Thank you!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

first you'll need to install this package to devDependencies:

npm i -D file-loader
yarn add -D file-loader

then you'll need to add the following to "rules" inside the webpack.config :

{
  test: /\.(png|jpe?g|gif)$/i,
  use: [
        {
          loader: 'file-loader',
        },
      ],
},
  • And finally, you'll need to switch the require with an import. maybe it can be pulled of with a require method but i'm not familiar enough with it.
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!