1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How can I make an Angular app load assets from correct level of an npm workspace

Discussão em 'Angular' iniciado por Sbodd, Julho 9, 2025.

  1. Sbodd

    Sbodd Guest

    I have an Angular application that lives inside an NPM workspace:

    workspace
    workspace/app1
    workspace/app2


    I have a 3rd party library integrated, and I need to include some assets in my build, so I do this in app1/angular.json:

    "styles": [
    "../node_modules/some_libary/Build/SomeLibrary.css",
    ],
    "scripts": [
    "../node_modules/some_library/Build/SomeLibrary.js"
    ],


    Both of my apps use the same version of some_library, so this works great - npm installs the library in workspace/node_modules/some_library, I point my angular.json at that path, all the files are there.

    But, a sad day comes and I have to update app1's version of some_library. Now I have

    workspace
    workspace/node_modules/some_library # this is the prior version, still in use in app2
    workspace/app1
    workspace/app1/node_modules/some_library # this is the newer version
    workspace/app2


    Now Angular's trying to pull the assets from the old library in workspace/node_modules instead of the new one in workspace/app1/node_modules.

    I can fix that by updating the paths in angular.json to just use ./node_modules instead of ../node_modules, and that works....until I update app2 to use the newer version of some_library, which means that suddenly I need to be loading the styles and scripts from ../node_modules instead of ./node_modules. This is, obviously, a bit error-prone.

    Is there a syntax I can use where ng build will automatically figure out which node_modules folder some_library is in?

    Continue reading...

Compartilhe esta Página