envs icon indicating copy to clipboard operation
envs copied to clipboard

Bit cannot find module

Open rap0so opened this issue 5 years ago • 7 comments

Describe the bug

I'm receiving error on tag an component containing @fortawesome

Steps to Reproduce

  1. Create/edit an component by adding a @fortawesome dependency, like this:
import { faUsers as iconGroup } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  1. Then use it: <FontAwesomeIcon={iconGroup} />
  2. Run bit tag [your-component]
  3. It will return an error 😞

Expected Behavior

Bit tag my component and let it ready to export 👀

Screenshots, exceptions and logs

In my opinion all errors is caused by the first one:

start of error msg: image

end of error msg: image

Specifications

  • Bit version: 14.7.4
  • Node version: v10.16.3
  • npm / yarn version: 1.21.1
  • Platform: Windows 10 Pro
  • Compiler / Tester (include version): "compiler": "bit.envs/compilers/[email protected]", "tester": "bit.envs/testers/[email protected]"

Additional context

I updated the compiler version but it keeps returning an error ❌

rap0so avatar Feb 17 '20 02:02 rap0so

What's the output of bit show <component> for the failing component?

itaymendel avatar Feb 17 '20 14:02 itaymendel

image

What's the output of bit show <component> for the failing component?

rap0so avatar Feb 17 '20 15:02 rap0so

I tried reproducing the issue, and I think I was successful is it. When I installed the @fortawesome/free-solid-svg-icons package, it asked me to add a peer dependency @fortawesome/fontawesome-svg-core. I don't see this peerdep configured for the component.

There's a reference here that shows how to do just that - https://docs.bit.dev/docs/overrides#components-dependencies

edit

I think this requires some additional explanation. Bit builds and tests each component in an isolated environment. When this environment is created, Bit installs all dependencies and components in it, and only then runs the build. So in this case, it seems that there was a peerdependency missing for the step to complete.

itaymendel avatar Feb 17 '20 16:02 itaymendel

I tried reproducing the issue, and I think I was successful is it. When I installed the @fortawesome/free-solid-svg-icons package, it asked me to add a peer dependency @fortawesome/fontawesome-svg-core. I don't see this peerdep configured for the component.

There's a reference here that shows how to do just that - https://docs.bit.dev/docs/overrides#components-dependencies

edit

I think this requires some additional explanation. Bit builds and tests each component in an isolated environment. When this environment is created, Bit installs all dependencies and components in it, and only then runs the build. So in this case, it seems that there was a peerdependency missing for the step to complete.

Cool! can you please explain it? like i'm 5 I'm really stuck here, step-by-step if u can

rap0so avatar Feb 17 '20 17:02 rap0so

Haha no worries :)

Bit defines each component's dependencies using static code analysis, meaning it reads the contents of the tracked files of each component, and logs all import and require statements. It then decides which of them is a peerDependencies, dependencies or a devDependencies according to this flow:

You can read more about it here.

When a package has a pee-dependency, and that peer-dependency is not explicitly imported in your component's source code, it's impossible for Bit to detect and add it. So what you need to do it to manually add that package to the component's peerDependencies using overrides.

In your case, the package @fortawesome/free-solid-svg-icons package requires a peer dependency to be present in order to work.. To see it, create a new project, run npm init -y and then npm i @fortawesome/free-solid-svg-icons and see that it is missing the peer dependency @fortawesome/fontawesome-svg-core.

Do add a peer-dependency to a Bit component, we use the overrides configuration. To do so, open your package.json file, and in the bit object add this entry:

{
    "overrides" : {
        "avatar": {
            "peerDependencies" : {
                "@fortawesome/fontawesome-svg-core": "+"
            }
        }
    }
}

itaymendel avatar Feb 17 '20 20:02 itaymendel

Haha no worries :)

Bit defines each component's dependencies using static code analysis, meaning it reads the contents of the tracked files of each component, and logs all import and require statements. It then decides which of them is a peerDependencies, dependencies or a devDependencies according to this flow:

You can read more about it here.

When a package has a pee-dependency, and that peer-dependency is not explicitly imported in your component's source code, it's impossible for Bit to detect and add it. So what you need to do it to manually add that package to the component's peerDependencies using overrides.

In your case, the package @fortawesome/free-solid-svg-icons package requires a peer dependency to be present in order to work.. To see it, create a new project, run npm init -y and then npm i @fortawesome/free-solid-svg-icons and see that it is missing the peer dependency @fortawesome/fontawesome-svg-core.

Do add a peer-dependency to a Bit component, we use the overrides configuration. To do so, open your package.json file, and in the bit object add this entry:

{
    "overrides" : {
        "avatar": {
            "peerDependencies" : {
                "@fortawesome/fontawesome-svg-core": "+"
            }
        }
    }
}

Hmmmm... i wrote it on package.json of avatar cmp:

  "bit": {
    "overrides": {
      "*": {
        "env": {
          "compiler": "bit.envs/compilers/[email protected]"
        },
        "peerDependencies": {
          "@fortawesome/fontawesome-svg-core": "+"
        }
      }
    }
  }

Did i do something wrong?

rap0so avatar Feb 18 '20 00:02 rap0so

what's the output of bit show <component> now?

itaymendel avatar Feb 18 '20 09:02 itaymendel