Comments (16)
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.
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.
peerdeps in v0.5.5 9f5c6de
from tsdx.
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.
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.
made a PR to do just that
from tsdx.
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.
That doesn't seem to fix it for me. I still get the same error.
from tsdx.
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.
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.
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.
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.
You don’t need to run yarn link if you build and import from the root
from tsdx.
I had the same issue, @petyosi solution worked for me.
from tsdx.
True
from tsdx.
@mikecousins you can always add a script to install the latest version of your lib
from tsdx.
Related Issues (20)
- Failed to install dependencies using `npx tsdx create mylib`
- Is TSDX no longer actively maintained? HOT 1
- Test files highlighted in red, plus jest error in console, but test passes
- TSDX build: semantic error TS2339: using 3rd party lib i18next HOT 2
- Module parse failed: Unexpected token HOT 1
- tailwindcss not applied after building package with tsdx HOT 1
- Unable to override tsconfig.compilerOptions.moduleResolution HOT 1
- Cannot install dependencies HOT 6
- Build fails with TS2339 but property exists on interface HOT 2
- not able to run storybook after typescript 5 HOT 1
- Not able to run test when creating new library due to typescript v5
- Example fails to run after creating a fresh lib HOT 1
- Test suite failed to run TypeError: The "path" argument must be of type string. Received undefined HOT 1
- Failure to run test HOT 7
- Upgrade to parcel v2, react 18 for example folder HOT 1
- Storybook not working on latest TSDX installation HOT 11
- Images not displaying in published package when using SVG or other image formats i.e jpg , png .
- Unabel to use .css files alongside .ts(x) files
- Getting error TS2305: Module has no exported member, but the member is exported
- tsdx build error : need help
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tsdx.