Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit export replace import/require to local scope #2780

Closed
azrulamir opened this issue Jun 30, 2020 · 2 comments
Closed

Bit export replace import/require to local scope #2780

azrulamir opened this issue Jun 30, 2020 · 2 comments

Comments

@azrulamir
Copy link

azrulamir commented Jun 30, 2020

Describe the bug

We are using different collections for our components. In the last couple of days we have begun starting having issues when in a component from one collection, imports a component from another. The imported component then changes its dependency path to come from the first components collection.

For example, lets say we have a component "A" in collection "first", and component "B" in collection "second". "A" imports "B" from "'@'bit/.second.B". The component builds without problem and can be exported, with the correct dependencies.

However, if we install the component "A" as a npm package, the path in the import has changed to "'@'bit/.first.B", which leads to build failure.

Has anyone come across this issue and knows how it can be solved?

Steps to Reproduce

  1. Tag the component
  2. Export the component with correct dependencies
  3. Install the exported component via npm
  4. Get an error below :-

ERROR Failed to compile with 1 errors
This dependency was not found:

  • @bit/affin-hwang-am.misc.tac in ./node_modules/@bit/affin-hwang-am.misc.add-new-bank/dist/AddNewBank.js

To install it, you can run: npm install --save @bit/affin-hwang-am.misc.tac

Expected Behavior

The error specify that we are missing a module @bit/affin-hwang-am.misc.tac.
HOWEVER the missing module should be located at @bit/affin-hwang-am.transaction.tac as per what we had defined correctly at our source code when we exported the component.

Screenshots, exceptions and logs

image
image

Specifications

  • Bit version: 14.8.2
  • Node version: v12.14.1
  • npm / yarn version: 6.13.4
  • Platform: Windows
  • Bit compiler (include version): bit.envs/bundlers/vue@2.6.21
  • Bit tester (include version): none

Additional context

Add any other context about the problem here.

@GiladShoham
Copy link
Member

GiladShoham commented Jun 30, 2020

I was able to reproduce this issue:

mkdir my-worksapce 
bit init
bit import bit.envs/compilers/babel --compiler

mkdir comp-b
touch comp-b/main.js
echo "export const a = 6;" > comp-b/main.js
bit add comp-b
bit tag comp-b
bit export scope1

mkdir comp-a
touch comp-a/main.js
bit add comp-a
bit tag comp-a
bit export scope2

echo "import {a} from '@bit/giladshoham.scope1.comp-b';" > comp-a/main.js
bit tag comp-a
bit export

npm i @bit/giladshoham.scope2.comp-a

now you can see in the comp-a in node_modules that in the src file you have
import {a} from '@bit/giladshoham.scope1.comp-b'
but in the dist file you have
import {a} from '@bit/giladshoham.scope2.comp-b'
This, of course, doesn't exist which leads to error in runtime

@davidfirst
Copy link
Member

davidfirst commented Jun 30, 2020

The issue has been fixed by #2781.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants