Comments (16)
@AaronPorts Have submitted a PR to have this resolved.
Given the holiday period, it may take some time to merge. If you can get by with the CommonJS configuration in the interim, that should hold until things get merged downstream, alternatively, just keep on with 0.31.0.
from typebox.
@SuperKXT @AaronPorts Hiya,
Looks like the Type Provider updates were published this morning. You can install the following which should solve ESM configuration issues.
@fastify/[email protected]
@sinclair/typebox@0.32.4
Have tested locally and things should be ok, but if you run into any issues, please let me know (I'm currently in the process of chasing down and documenting ESM issues, so any issues reported are very helpful)
Cheers!
from typebox.
👍 Everything works on my end (using CJS)
from typebox.
Would you like to submit a PR to the Fastify Type Provider project to bump the peer dependency range?
Sure!
from typebox.
@AaronPorts Hi
Have just re-tested and things should be working ok on @fastify/type-provider-typebox: 3.6.0. I can only really recommend trying to clean out node_modules and reinstalling to ensure there's no transient older versions of TypeBox installed. My hunch is that TS may be having difficulty resolving for multiple installed versions of TypeBox, but outside of this, I don't have much additional information to go on.
Edit: Sorry, I have been able to reproduce this on 3.6.0. Will investigate.
from typebox.
Heroic! Thank you! Will revisit this discussion if I encounter any other issues.
from typebox.
@dwickern Hi, thank you for taking the time to test!
Sadly, didn't get a lot of community testing over the week as I'd hoped for (I guessing it's quite rare for people to check issue thread notices). Still, will be pushing out this revision this afternoon. Will be tracking any significant issues over the next few days, but hoping for the best! :)
Thanks again
S
from typebox.
Upgrading to 0.32.3
broke @fastify/type-provider-typebox
for me.
The generics don't seem to work properly and the types all default to unkown
.
from typebox.
@SuperKXT Hi,
The @fastify/type-provider-typebox
package was tested prior to release. It should be working fine (as the provider inference hasn't changed from 0.31.0 to 0.32.0). See link below where the provider is inferring types only available on 0.32.0.
import Fastify from 'fastify'
import { Type, TypeBoxTypeProvider } from '@fastify/type-provider-typebox'
const fastify = Fastify().withTypeProvider<TypeBoxTypeProvider>()
fastify.get('/', {
schema: {
// Mapped Types Only Available in Revision 0.32.0
body: Type.Mapped(Type.TemplateLiteral('b${0|1}${0|1}${0|1}${0|1}'), K => Type.String())
}
}, (req) => {
req.body.b0000
req.body.b0001
req.body.b0010
req.body.b0011
// ..
req.body.b1111
})
You could try delete the node_modules directory and install the packages. Also, just ensure you've only got 0.32.0 installed. Let me know if this helps.
Cheers
S
from typebox.
Thank you for the quick response!
I have narrowed that the issue only happens if I import Type
from typebox directly but does not happen if I import from @fastify/type-provider-typebox
.
The issue does not happen in the playground, but I've created a minimal repro of the issue here.
Things I've tried:
- Remove the lock file and node_modules and reinstall.
- Use npm instead of pnpm.
from typebox.
@SuperKXT Hiya,
I wondering if this might be to do with the type provider requiring the updated peerDependency (which is currently locked at <= 0.31.0). This range is usually updated after a TB minor revision, but has yet to be done for 0.32.0.
https://github.com/fastify/fastify-type-provider-typebox/blob/main/package.json#L8
Running on the TSP, things still seem to resolve correctly.
Would you like to submit a PR to the Fastify Type Provider project to bump the peer dependency range?
from typebox.
Still having this issue with typebox: 0.32.4 and @fastify/type-provider-typebox: 3.6.0.
from typebox.
Ok, I've been able to resolve the issue by updating tsconfig.json to the following.
{
"module": "CommonJS",
"moduleResolution": "Node10",
"verbatimModuleSyntax": false,
}
I think the problem here is that TypeBox 0.32.0 has begun support for both CJS and ESM, however the Type Provider is CJS only.
What I think is happening is that TS is importing CJS types from the Provider (which works), but when importing Type
from @sinclair/typebox
directly AND configuring a project for module: NodeNext
, this causes TS to import the ESM definitions from TypeBox (not the CJS definitions used as used the Provider), causing inference errors.
The above tsconfig.json update should ensure that module resolution is kept to CJS only (inline with the Provider). Ill have a look for some other alternative (and hopefully simpler) solutions (Unfortunately, supporting ESM has not been without it's challenges).
Let me know if this helps
from typebox.
So, taking a deeper look into this, I don't think there's much that can be done TypeBox side to make things easier here, other than dropping support for ESM which is not really a viable option (as I had hoped to eventually drop support for CJS (one day)).
For now you will need to configure your projects for module resolution Node10 and module CommonJS. As below.
{
"module": "CommonJS",
"moduleResolution": "Node10",
"verbatimModuleSyntax": false,
}
One possible solution outside of TypeBox might be to update the Type Provider to support both ESM and CJS (as TypeBox does), which would allow for both ESM and CJS TS configuration, however it's a bit of work to do this (as the tooling for dual publishing is quite bad), and any updates made to the Provider would likely need to pass through Fastify's TypeScript team, which given the nature of the issue, I would expect a PR to need a really good review and team consensus reached on how best to dual publish (I spent a few weeks working out the TB build, things are very complex). I haven't the bandwidth for this currently, but could potentially look at things semi early next year.
@AaronPorts Again, keep me posted if these configurations resolve things your side.
from typebox.
@sinclairzx81 Yes, it resolves the issue, but I have some packages (like got
for ex.) that require esm. So this workaround is not drop in replacement in my case.
from typebox.
@AaronPorts Thanks for getting back
Hmmm, Not too sure what could be done TypeBox side as it "should" be configured correctly. The following links show the resolution TS uses for various module configurations.
As you can see, the Provider is resolving CJS despite configurations for Node16 (ESM). This would suggest the Provider does need updating to support ESM resolution for Node16. If this was done, it should resolve this issue, however it's likely going to require the Provider to dual publish (which unfortunately is less trivial than it should be)
Would you like to draft an issue on the Type Provider package?
from typebox.
Related Issues (20)
- JsonTypeBuilder#Record not passing on options HOT 1
- No implicit defaults on Value.Create() HOT 5
- [BUG] Value.create caches the default date HOT 1
- Feature request: Value.Assert and TypeCheck.Assert HOT 3
- [Feature Request?] allow more flexible input for string pattern HOT 3
- Individual types imports naming conflict with native classes HOT 4
- Strict error: Unknown type HOT 2
- Maximum call stack size exceeded. HOT 2
- TUnion of literals from const array HOT 2
- "Value.Clean" doesn't work with Unions of objects with prohibited additionalProperties HOT 3
- JS floating point precision bug causes multipleOf validation to fail HOT 4
- Tuple with rest items (or Array with prefixedItems) HOT 2
- useDefaults HOT 3
- Support for discriminator HOT 1
- Support for self-referencing fields of recursive type HOT 2
- Property '[Kind]' is missing in type 'TObject' but required in type 'TObject<TProperties>' HOT 3
- [feat] Bail / Early Cancel Mode HOT 1
- Setting Description HOT 1
- Schema dependency using Typebox HOT 3
- Composite working uncorrect HOT 5
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 typebox.