typespec icon indicating copy to clipboard operation
typespec copied to clipboard

Missing imports/exports for emitter-framework

Open marron-at-work opened this issue 3 years ago • 10 comments

I am working on some language emitters and ran into an issue trying to use the new emitter-framework. Specifically it looks like there are missing imports/exports that cause compiler errors when trying to build a new emitter using it.

When I followed the example in the documentation I was missing at least the CodeTypeEmitter type and the code tag. I was able to hand hack the index.js and index.ts.d files to export these and everything then worked fine.

I am assuming it is just a missing set of exports in the index.ts file.

marron-at-work avatar Mar 17 '23 04:03 marron-at-work

This is working for me in a separate project:

import { CodeTypeEmitter, code } from "@typespec/compiler/emitter-framework";

Are you perhaps missing the /emitter-framework suffix in the import?

nguerrera avatar Mar 17 '23 14:03 nguerrera

Looks like the docs don't point this out that emitter-framework exports are separated like that so we should fix that.

nguerrera avatar Mar 17 '23 14:03 nguerrera

Hmm, that is odd. I just copy pasted that import and see the same errors.

I have a public repo that I setup where this reproduces: Github repro (https://github.com/BosqueLanguage/TypeSpecToBosque)

Platform is: Ubuntu: 22.04 Node: 16.14.0 TSC: 4.7.4

TypeSpec NPM package: 0.42.0 (and 0.41.0)

marron-at-work avatar Mar 17 '23 16:03 marron-at-work

@marron-at-work Ah, thanks for the repro! Try changing "moduleResolution" in tsconfig.json from "node" to "node16". That fixed it for me.

nguerrera avatar Mar 17 '23 16:03 nguerrera

Ah, hmm, it got rid of squiggle in the IDE, but build is still failing. Continuing to look.

nguerrera avatar Mar 17 '23 16:03 nguerrera

Same here but then I updated to TS 5.0 and it now builds too.

marron-at-work avatar Mar 17 '23 16:03 marron-at-work

😀 Yep, I also just discovered that it was because I had TS 4.8.4 on global path. FWIW, turns out 4.9.x is sufficient and that's what we're on.

Consider putting a "devDependency" on "typescript" in package.json so that build can always use the version you specify.

nguerrera avatar Mar 17 '23 17:03 nguerrera

Note to self, cover this in docs:

  • [ ] /emitter-framework in imports
  • [ ] "node16" moduleResolution in tsconfig.json
  • [ ] typescript minimum version 4.9.x

nguerrera avatar Mar 17 '23 17:03 nguerrera

Great, I think this resolves everything for me. It sounds like you have some documentation items open from this so I'll leave it for you close it as needed.

Thanks again!

marron-at-work avatar Mar 17 '23 17:03 marron-at-work

est: 2

markcowl avatar Mar 21 '23 16:03 markcowl