Comments (17)
Yes, I've seen the CRA recommendation for installing @types/node
but it seems crazy since in a CRA app you don't have all of Node available. With @types/node
hanging about you can do things like import { readFile } from 'fs'
which in a web app, well... obviously isn't going to work.
I always switch @types/node
out for @types/webpack-env
which declares process.env
and the webpack internals. process.env
is all I think from @types/node
which is actually available in a CRA/Webpack app.
from unified.
Coming soon to a package registry near you!
from unified.
Continueing the discussion from rehypejs/rehype-document#9 (review):
I believe the only package causing issues is vfile
, because it depends on Buffer
.
In postcss itβs solved by not using string | Buffer
, but string | { toString(): string }
https://github.com/postcss/postcss/blob/master/lib/postcss.d.ts#L24-L26
This allows to somewhat loosely depend on Buffer
as a type, but not depend on the entire node
types that cause conflicts in a dom or webworker environment.
from unified.
@damonmaria @ChristianMurphy We've discussed this issue in here.
I also agree with @damonmaria 's opinion.
So I think the best solution is:
- Move
@types/unist
todevDependencies
(without adding itpeerDependencies
) - Add description, which is installing
@types/unist
, to readme.md or other place for typescript users.
from unified.
That's NOT crazy. React is designed to be isomorphic for ssr. Using @types/node
is common when you are developing with webpack.
And unified is also needing it because it accepts Buffer.
from unified.
So I think the best solution is:
Move @types/unist to devDependencies (without adding it peerDependencies)
Add description, which is installing @types/unist, to readme.md or other place for typescript users.
β @Rokt33r
Could you elaborate on how that would affect users using unified deep down in, say, CRA?
from unified.
@wooorm Thanks! I am looking forward to the next release! π
from unified.
cross posting this: syntax-tree/unist-util-is#14
Yarn 2 may cause challenges with this approach.
from unified.
@ChristianMurphy that is likely to be the case as my comment was from a year ago π i don't think we're experiencing this issue now anymore but I'll double check it.
from unified.
/cc @Rokt33r
from unified.
The actual base issue I'm having is that @types/node, @types/react-native and @types/styled-components in some combination in different versions declare 'base things' (like console
and FormData
) differently. Which causes Typescript to bork. I'm in a web app so @types/node
shouldn't even be there. But at the moment react-scripts
is forcing that to happen (through this package).
Sorry, I can't speak to what unified
should do as I'm not even a direct user of it.
from unified.
unified
is a pluggable interface. It accept a parser, a compiler and some transformers. For example, remark
is actually a unified instance with remark-parse
and remark-compiler
.
I think dedupe might help. https://yarnpkg.com/lang/en/docs/cli/dedupe/
But, it seems you need to install @types/node when using cra with typescript. https://facebook.github.io/create-react-app/docs/adding-typescript
from unified.
Hi, I agree with the idea to move @types/*
packages to devDependencies
, and I hope strongly. π
Because remark doesn't work on this PR TypeStrong/ts-loader#908. π
(Please see also TypeStrong/ts-loader#908 (comment))
from unified.
@Rokt33r Do you have any thoughts on #45 (comment)?
from unified.
Curious why there needs to be @types/vfile
since it seems the vfile
repo has types in it already? Are those types copied to DefinitelyTyped
or something?
I ask since the inclusion of the types in DefinitelyTyped
causes this library to depend on @types/node
, which is causing my frontend app to have @types/node
present. It happens because react-scripts
many layers down depends on unified
(react-scripts -> @svgr/webpack -> @svgr/plugin-jsx -> unified -> @types/vfile
). And this is annoying since now the TypeScript compiler is telling me that I can use Node builtins and libraries like fs
in my frontend web app, which in reality would make it crash at runtime.
from unified.
@osdiab you may be running an older version of Unified, unified doesn't depend on @types/vfile
in the latest version, if you have follow up questions, feel free to open a thread at https://spectrum.chat/unified/type-definitions
from unified.
@remcohaszing Thanks for the idea, that approach is definitely worth exploring, opened vfile/vfile#54 with a version of this idea.
from unified.
Related Issues (20)
- Update vfile to 4.2.1 HOT 1
- Logo not readable on github dark mode HOT 1
- Next major for the ecosystem HOT 46
- Dependencies need to be ESM HOT 6
- 3rd overload signature of `FrozenProcessor.run` should accept `ParseTree` instead of `CompileTree` HOT 5
- this.use() doesn't respect plugin order when combined with unified().use() HOT 6
- Support async compilers HOT 31
- Rethink how `*-stringify` should work HOT 16
- Throw on preset w/ neither `settings` nor `plugins` HOT 1
- unify AST types HOT 1
- Support `Node` typeParam in `Pluggable` and `PluggableList` HOT 9
- Notion Block AST HOT 4
- Error: No overload matches this call after library update. HOT 5
- Type errors on new major version β 11.0.2 HOT 5
- TypeScript error when doing simple unified markdown pipeline HOT 3
- CallableInstance throws error in older ECMA 5 targets HOT 6
- remove `is-plain-obj` deps HOT 9
- Make VFileContents generic to support processors that return objects HOT 3
- tsc reports incorrect / missing types HOT 14
- VFile types do not support property result HOT 6
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 unified.