Code Monkey home page Code Monkey logo

cra-monorepo's Introduction

cra-monorepo

This is an example of creating a monorepo using create-react-app.

It does not work currently, See CRA issue #3676.

Repo Structure

cra-monorepo
|--- myapp (CRA)
|    `--- src
|         `--- components
|              `--- Home.js
`--- shared (shared components)
     `--- components
          `--- Profile.js

The .env file under myapp has been set up to import source from ./src and ../shared:

NODE_PATH=./src:../shared

Issue Before Ejecting

cd myapp
yarn
yarn start

You will see the following error:

Failed to compile.

../shared/components/Profile.js
Module parse failed: Unexpected token (5:16)
You may need an appropriate loader to handle this file type.
| class Profile extends React.Component {
|     render() {
|         return (<div>Profile</div>);
|     }
| }

Basically CRA fails to recognize Profile.js as a JSX file.

If I remove the Profile component from myapp/src/App.js, the app works correctly, demonstrating that local components such as Home work perfectly. It's only the components in the shared folder that have the problem.

Issue After Ejecting

To fix the issue. I have ejected.

  • I added an appShared export in paths.
  • I added paths.appShared to the webpack config so that the jsx files are passed through eslint and babel. See here and here.

This allowed the build to progress a bit further, but now something else is tripping up on shared/components/Profile.js, not recognizing it as a jsx file. Here's the error:

../shared/components/Profile.js
Syntax error: Unexpected token (5:16)

  3 | class Profile extends React.Component {
  4 |     render() {
> 5 |         return (<div>Profile</div>);
    |                 ^
  6 |     }
  7 | }
  8 |

cra-monorepo's People

Contributors

nareshbhatia avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.