Angular code smell "Either remove this import or add it as a dependency." when using an interface I wrote. How can I make my code compliant?
Asked Answered
E

2

7

I'm new to UI development so forgive me if this isn't angular. I'm using Angular 8 and typescript here. Anyways I created a pop-up modal that I wan't to use throughout my website. It looks great but when I plug it into my components like this

import { IPopUpOptions, IPopUpButton } from 'src/app/modals/pop-up-modal/pop-up-options-interface';

My SonarQube CI/CD pipeline says "Either remove this import or add it as a dependency. Dependencies should be explicitly listed in the package.json file. Importing a module that is not declared as a dependency makes it an implicit one and is bound to create problems." What does this mean? How can I use my pop-up properly so that it abides by this rule?

Eugenie answered 9/1, 2020 at 18:39 Comment(2)
Maybe try adding './' to your import path: './src/app/modals/pop-...'? Without that, it might be seen as a dependency import (i.e., from node_modules) rather than a file system import.Flashover
My hero @MikeJ! Write that as the answer so I can give you credit =]Eugenie
F
14

Try adding './' to your import path: './src/app/modals/pop-...'. Without that, it might be seen as a dependency import (i.e., from node_modules) rather than a file system import.

Flashover answered 10/1, 2020 at 20:9 Comment(3)
what if we use @ as import? eg nx library?Hydrophilous
@mikeJ Can you help with question ? from Weijing Jay Lin commentAccumulator
@WeijingJayLin did you find solution for the same ? I', also facing similar problem ?Exchequer
F
0

You can configure the rule with a whitelist property. https://community.sonarsource.com/t/javascript-typescript-false-positive-with-absolute-imports/33290

Feuillant answered 7/12, 2023 at 22:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.