Bit: Components do not compile on bit.dev

Created on 27 Aug 2019  路  8Comments  路  Source: teambit/bit

Description

I am trying to view my components at bit.dev after exporting them from my workspace. When I view an individual component I get the following error: Unexpected token (10:7)

Context and additional information

  • Bit version: @latest
  • Yarn version: v1.6.0
  • OS: Windows 10 64-bit

I've attached a screenshot:
screenshot-bit dev-2019 08 27-12_10_39

typhelp wanted

Most helpful comment

Hey, you did not import a compiler, so your files are not compiled in the playground.
You can fix this by importing the react compiler in your project with this command:
bit import bit.envs/compilers/react -c

So just need to import the compiler, run the following commands and it will work:
bit import bit.envs/compilers/react -c - to import react compiler
bit build - bit build all your component with react compiler
bit tag -a - tag your component with a new version
bit export <YOUR COLLECTION> - to export your tagged components

All 8 comments

Hey, you did not import a compiler, so your files are not compiled in the playground.
You can fix this by importing the react compiler in your project with this command:
bit import bit.envs/compilers/react -c

So just need to import the compiler, run the following commands and it will work:
bit import bit.envs/compilers/react -c - to import react compiler
bit build - bit build all your component with react compiler
bit tag -a - tag your component with a new version
bit export <YOUR COLLECTION> - to export your tagged components

Also, you need to set react and react-dom as peer dependencies in your project, or just set overrides in bit, so it will work in bit.dev, and also in other projects that will consume your components, because they have already install react and react-dom as dependencies.

more info: https://docs.bit.dev/docs/conf-files.html#setting-specific-component-configurations

Hi @JoshK2 !

Thanks for your help!!! 馃拠鈥嶁檪

Followed your instructions and it is now working as expected. 馃挴

Hey @AmoDinho, I created a pull request to fix the peer dependencies in your project.
https://github.com/pimp-my-book/umqombothi-component-library/pull/30

Also, If your project is only a component library, and will not run alone, you can set the peer dependencies in the package.json like this:

...
"dependencies": {
    "react-scripts": "3.0.1",
    "styled-components": "^4.3.2"
  },
"peerDependencies": {
          "react": "16.8.6",
          "react-dom": "16.8.6"
 }
...

and not in bit objects.

@AmoDinho, it's better for you to merge this pr:
https://github.com/pimp-my-book/umqombothi-component-library/pull/31
because it's removed unnecessary dependencies in your project and set them as a peer.
And like this, you don't need to use the overrides option in bit.

Hi @JoshK2 , I've just merged it.

Really appreciate the help from the both of you. 馃

@AmoDinho with pleasure.
Nice button 馃槈
image

@JoshK2 Thanks!

Quick question, is there a way to run bit locally similar to Storybook?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nvthuong1996 picture nvthuong1996  路  13Comments

ranm8 picture ranm8  路  16Comments

FredyC picture FredyC  路  20Comments

AlexanderKaran picture AlexanderKaran  路  10Comments

viiralt picture viiralt  路  11Comments