question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Yarn workspaces support

See original GitHub issue

Bug Report

Describe the bug

Compilation fail when importing components from another yarn workspace.

To Reproduce

  1. Create one docz workspace and one shared workspace
  2. Create components on shared
  3. Import them on docz
  4. See error
Module parse failed: Unexpected token (11:2)
You may need an appropriate loader to handle this file type.
| 
| export default () => (
>   <Touchable onPress={() => alert('pressed')}>
|     <Text style={styles.text}>Shared Button</Text>
|   </Touchable>

 @ ./src/index.mdx 9:0-61 66:93-99
 @ ./.docz/app/imports.js
 @ ./.docz/app/index.jsx
 @ multi ../node_modules/docz-core/node_modules/babel-polyfill/lib/index.js ./.docz/app/index.jsx

Environment

  • OS: macOS 10.14
  • Node/npm version: Node 8.11.3 / npm 5.6

Additional context/Screenshots If I move the docz code to shared it will work. It only works if the components are in the same “project”. If you try to import from another workspace it fails.

If you setup docz in the root directory (outside all workspaces) it fails as well, but with another error.

image

image

doczrc.js

module.exports = {
  themeConfig: {
    colors: {
      primary: 'black',
    },
  },
  typescript: true,
}

docz package.json

{
  "name": "docz",
  "version": "0.0.1",
  "scripts": {
    "start": "docz dev",
    "build": "docz build"
  },
  "dependencies": {
    "shared": "0.0.1"
  },
  "devDependencies": {
    "docz": "^0.10.2"
  }
}

docz/src/index.mdx

---
name: Hello world
---

import Button from 'shared/src/components/common/Button.tsx'

# Hello world

<Button>Click</Button>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
aarshawcommented, Oct 2, 2018

Ended up using something similar to this ^ …feels king of hacky but works

Updated doczrc.js to the following:

import path from 'path'

const modifyBundlerConfig = config => {
  config.module.rules[0].include.push(path.join(__dirname, '..', 'SHARED_PACKAGE_NAME'))

  return config
}

export default {
  modifyBundlerConfig,
}
2reactions
pedronauckcommented, Sep 23, 2018

For sure @brunolemos I agree with you that is related to docz instead of yarn. But, is not a “problem”, is an architecture decision. It’s not a good practice import from other packages in a monorepo without transpiling and since they will be in the node_modules they won’t be transpiled. What you can do in this case is change the loader do transpile from a specific node_modules since we’re ignoring all node_modules folder to be transpiled.

About create-react-app I saw this week on twitter that they’re dropping support for monorepo. So, I think that change the entire structure to support monorepo can be a good choice.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Workspaces - Yarn
Workspaces are a new way to set up your package architecture that's available by default starting from Yarn 1.0. It allows you to...
Read more >
Yarn workspaces — monorepo beginner's guide | The Startup
In this guide, we will create a sample monorepo using Yarn workspaces. It will contain both back-end (express) and front-end (react) ...
Read more >
Scaling out JavaScript Monorepos with Yarn Workspaces
Workspaces : Yarn can now manage dependencies across many independent projects in the same repository. Instead of having several big node_modules ...
Read more >
Yarn Workspaces: Organize Your Project's Codebase Like A Pro
Yarn is a package manager by the folks at Facebook, and it has a great feature called Yarn workspaces. Yarn workspaces let you...
Read more >
Support yarn workspaces (better indexing of node_modules ...
Yarn workspaces works by creating symlinks between your workspace projects in the parent workspaces node_modules folder - and also pulls all dependencies which ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found