Giter VIP home page Giter VIP logo

Comments (16)

mkaradeniz avatar mkaradeniz commented on July 16, 2024 3

I think I found the problem. I was testing it using yarn link and I couldn't get it to work without removing the devDependency. Publishing a package based on 0.5.5 and using that worked fine. Thanks you all!

from tsdx.

mikecousins avatar mikecousins commented on July 16, 2024 2

This doesn't work if you're trying to deploy the example site to Netlify or something similar. Is there any other way to accomplish this?

from tsdx.

swyxio avatar swyxio commented on July 16, 2024 1

peerdeps in v0.5.5 9f5c6de

from tsdx.

petyosi avatar petyosi commented on July 16, 2024 1

Facing the same problem; I don't think it is caused by tsdx itself - hooks are quite picky when multiple react instances are present - see facebook/react#14257. Tried doing the recommendations from there; Linked the package react using yarn link and added "react": "link:../node_modules/react" to package.json. Did not work for me.

The solution which worked for me:

  • remove package.json/tsconfig.json from example
  • install parcel as dev dependency in the package root.
  • re-point the import in example/index.tsx to 'src/index.tsx`.
  • start the example from the root with parcel example/index.html

Probably not perfect, but at least it works quite fast.

from tsdx.

jaredpalmer avatar jaredpalmer commented on July 16, 2024 1

I think the solution I like best now is to use Parcel's alias like so:

  "name": "example",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "parcel index.html"
  },
  "dependencies": {
    "react-app-polyfill": "^1.0.0"
  },
  "alias": {
    "react": "../node_modules/react",
    "react-dom": "../node_modules/react-dom"
  },

  "devDependencies": {
    "@types/react": "^16.8.15",
    "@types/react-dom": "^16.8.4",
    "parcel": "^1.12.3",
    "typescript": "^3.4.5"
  }
}```

from tsdx.

swyxio avatar swyxio commented on July 16, 2024 1

made a PR to do just that

from tsdx.

Guria avatar Guria commented on July 16, 2024

The right solution is to put react and react-dom to peerDependencies + devDependencies (to be able still develop and test library itself) and never in a regular dependencies.

from tsdx.

mkaradeniz avatar mkaradeniz commented on July 16, 2024

That doesn't seem to fix it for me. I still get the same error.

from tsdx.

Guria avatar Guria commented on July 16, 2024

have you tried to drop node_modules and lock files and reinstall deps?
devDeps + peerDeps in a library shouldn't lead to a duplicated react in node_modules.
Use npm ls react or yarn list react to check that you have no duplicates.

from tsdx.

jaredpalmer avatar jaredpalmer commented on July 16, 2024

Yes, we should add react to peer deps and dev deps in the template and keep them as regular deps in the example directory. This is how I do it in Formik. IIRC Formik doesn’t place react-dom as a peer dep, only a dev dep, so it can be used with react native.

from tsdx.

mkaradeniz avatar mkaradeniz commented on July 16, 2024

Sorry. I did get it work in an CRA-Project with the published package. But creating a project based on 0.5.5, adding a hook, and then trying to use the component in the provided example setup is still not working for me. Am I doing something wrong? Repo: https://github.com/mkaradeniz/tsdx-hooks-problem-example

from tsdx.

mkaradeniz avatar mkaradeniz commented on July 16, 2024

Yeah, the "react": "link:../node_modules/react" didn't work for me directly either. Only after installing the dependencies without react & react-dom and then adding "react": "link:../node_modules/react" & "react-dom": "link:../node_modules/react-dom" after installing works. At least as long you don't yarn again.

Thanks for your workaround!

from tsdx.

jaredpalmer avatar jaredpalmer commented on July 16, 2024

You don’t need to run yarn link if you build and import from the root

from tsdx.

DennisKo avatar DennisKo commented on July 16, 2024

I had the same issue, @petyosi solution worked for me.

from tsdx.

jaredpalmer avatar jaredpalmer commented on July 16, 2024

True

from tsdx.

swyxio avatar swyxio commented on July 16, 2024

@mikecousins you can always add a script to install the latest version of your lib

from tsdx.

Related Issues (20)

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.