question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Static images not loading from assets library

See original GitHub issue

I am trying to load the images from shared assets library in to stories i created with libraries in Nx workspace. I have made necessary changes for that. but images loading in images.

my Main.js

staticDirs: [{ from: "../../../libs/shared/assets/src/lib/images/", to:'./assets/images/' }],

on complier I am getting the following information:

info => Serving static files from ./.\libs\shared\assets\src\lib\images\ at /.\assets\images

But stories on browser: Loaded with no image. Please help.

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mrtcntncommented, Aug 8, 2022

You should be able to do this directly from your project.json

There’s an assets option that allows you to specify different locations for your assets. Have you tried that?

I have the setup you described, linking my assets like this in my Next.js app’s project.json:

"build": {
      "executor": "@nrwl/next:build",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "root": "apps/app",
        "outputPath": "dist/apps/app",
        "assets": [
          {
            "input": "libs/ui/static",
            "glob": "**/*",
            "output": ""
          },
          {
            "input": "libs/ui/icons/assets",
            "glob": "**/*",
            "output": "assets/icons"
          }
        ]
      },
      "configurations": {
        "production": {},
        "development": {}
      }
    }

Where I have the assets at libs/ui/icons/assets and trying to load my assets using <img src="/assets/icons/icon.png">. This setup worked fine in previous versions but crashed with 15.5.4. In #11431 I saw this comment. Updating copy-webpack-plugin might have changed the previous behavior.

0reactions
github-actions[bot]commented, Aug 31, 2022

This issue has been automatically marked as stale because it hasn’t had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Images not loading from assets folder in Angular
Topic: Images not loading from assets folder in Angular ... in app.component.html. assets and images folder location: projectfolder\src\assets\images ...
Read more >
Angular 6 Failing To Load Images From Assets [duplicate]
Any idea why this is not working? My image.png is in my assets folder which is located at src/assets/image.png. Update: So we did...
Read more >
Images, fonts, and assets - Storybook - JS.ORG
We recommend serving static files via Storybook to ensure that your components always have the assets they need to load. We recommend this...
Read more >
7 Reasons Why Images Are Not Loading on Your Website
7 Reasons Why Images Are Not Loading on Your Website · 1. Incorrect File Paths · 2. Files Names Misspelled · 3. Wrong...
Read more >
HTML and Static Assets
You have thousands of images and need to dynamically reference their paths. Some library may be incompatible with Webpack and you have no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found