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

Example in React template throws cannot resolve dependency 'react' -- only with Lerna monorepo #116

Closed
kirjai opened this issue May 29, 2019 · 4 comments
Labels
kind: support Asking for support with something or a specific use case scope: docs Documentation could be improved. Or changes that only affect docs scope: integration Related to an integration, not necessarily to core (but could influence core) topic: monorepo Related to Lerna monorepos

Comments

@kirjai
Copy link
Contributor

kirjai commented May 29, 2019

Current Behavior

When creating a new library with tsdx, by running npx tsdx create some-name and choosing the react template, when attempting to run the example, the build fails with a Cannot resolve dependency 'react' error.

Expected behavior

Build should not fail.

Suggested solution(s)

From what I understand, because the package.json inside example defines react and react-dom as aliases to the root directory node_modules, and the root package.json defines react as a peer dependency, we end up in a situation where react is never installed, hence the cannot resolve dependency error.

Reverting the changes introduced in #88 locally, solves the problem. So removing the aliases and defining react and react-dom as dependencies inside example/package.json works as expected.

Your environment

Software Version(s)
TSDX 0.5.12
TypeScript 3.4.5
Browser n/a
npm/Yarn 1.9.4
Operating System Mac OS 10.14.2
@swyxio
Copy link
Collaborator

swyxio commented May 29, 2019

hello, the reason we did #88 this is because we need to ensure the same instance of react inside example as we do in the hooks lib.

the root package.json defines react as a peer dependency, we end up in a situation where react is never installed, hence the cannot resolve dependency error.

i'm not sure about this. we install react here: https://github.com/palmerhq/tsdx/blob/master/src/index.ts#L222

@swyxio
Copy link
Collaborator

swyxio commented May 29, 2019

i just tested a freshly created library from v0.5.12, using yarn it seems fine. so perhaps this is an npx issue.

@kirjai
Copy link
Contributor Author

kirjai commented May 29, 2019

Thanks for looking into this.

So I did some digging just now, prompted by your comments, and realized that when i was trying to replicate this issue, I was doing so inside a mono repo, managed by lerna. So looks like that's the reason the alias approach doesn't work for me.

As far as i understand, in a mono repo, some dependencies are installed in the root of the repo, that's why react and react-dom are actually missing from the node_modules in a fresh directory created by tsdx, they are present in the mono repo root node_modules. Therefore, react and react-dom aren't available in the location point to by the alias.


So not sure if this is a use case that tsdx supports or should support, but in case it's not, perhaps it's worth to mention this and the potential workaround in the react template README?
I'm happy to submit a PR for that if you it would be worth it.

@swyxio
Copy link
Collaborator

swyxio commented May 29, 2019

sure, PR welcome. basically users of tsdx should feel comfortable enough modifying the templated pkg.json to their needs, i dont think we wanna support every use case. but i'm happy to document it.

@kirjai kirjai closed this as completed May 30, 2019
@agilgur5 agilgur5 added the kind: support Asking for support with something or a specific use case label Mar 19, 2020
@agilgur5 agilgur5 changed the title Example in React template throws cannot resolve dependency 'react' Example in React template throws cannot resolve dependency 'react' -- only with Lerna / monorepo Mar 19, 2020
@agilgur5 agilgur5 added scope: docs Documentation could be improved. Or changes that only affect docs scope: integration Related to an integration, not necessarily to core (but could influence core) labels Mar 19, 2020
@agilgur5 agilgur5 changed the title Example in React template throws cannot resolve dependency 'react' -- only with Lerna / monorepo Example in React template throws cannot resolve dependency 'react' -- only with Lerna monorepo Mar 20, 2020
@agilgur5 agilgur5 added the topic: monorepo Related to Lerna monorepos label Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: support Asking for support with something or a specific use case scope: docs Documentation could be improved. Or changes that only affect docs scope: integration Related to an integration, not necessarily to core (but could influence core) topic: monorepo Related to Lerna monorepos
Projects
None yet
Development

No branches or pull requests

3 participants