cmorten / opine

Minimalist web framework for Deno ported from ExpressJS.
https://github.com/cmorten/opine/blob/main/.github/API/api.md
MIT License
854 stars 43 forks source link

Error when i start script with --no-check flag #97

Closed 4ov closed 3 years ago

4ov commented 3 years ago

Issue

Setup:

I'm getting an error while i disable ts check for my app

Details

command : deno run -A --no-check serve.ts output :

error: Uncaught SyntaxError: The requested module './CtxLike.ts' does not provide an export named 'CtxLike'
export { CtxLike } from "./CtxLike.ts";
~~~~~~~
    at <anonymous> (<https://deno.land/x/evt@v1.9.11/lib/types/interfaces/index.ts>:5:1)

code i use :

import { opine } from "https://deno.land/x/opine@1.0.0/mod.ts";

const app = opine();

app.get("/", function(req, res) {
  res.send("Hello World");
});

app.listen(3000);
cmorten commented 3 years ago

Hi @lowray, thanks for raising this πŸ˜„

Having read the Deno manual (REF: https://deno.land/manual@v1.6.2/getting_started/typescript#code--no-checkcode-option) I believe this may be an issue with @garronej's https://github.com/garronej/evt library which Opine uses for it's eventing interface 😒. Namely check out this part of the --no-check docs:

To make the most of skipping type checks, --no-check transpiles each module in isolation without using information from imported modules. This maximizes potential for concurrency and incremental rebuilds. On the other hand, the transpiler cannot know if export { Foo } from "./foo.ts" should be preserved (in case Foo is a value) or removed (in case Foo is strictly a type). To resolve such ambiguities, Deno enforces isolatedModules on all TS code. This means that Foo in the above example must be a value, and the export type syntax must be used instead if Foo is a type.

Which I believe may be the issue as CtxLike which is re-exported in the index.ts file in your error message (REF: https://deno.land/x/evt@v1.9.11/lib/types/interfaces/index.ts#L5) is an interface, not a value, and therefore not found when the --no-check flag is provided.

...
export { CtxLike } from "./CtxLike.ts";
...

I wonder if instead the code should be something like...


/** https://docs.evt.land/api/ctx */
export type Ctx<Result> = import("./Ctx.ts").Ctx<Result>;
export type DoneOrAborted<Result> = import("./Ctx.ts").DoneOrAborted<Result>;
export type CtxLike = import("./CtxLike.ts").CtxLike; // Exported as a type in the same fashion as everything else?
/** 
 * Minimal interface that an object must implement to be a valid context argument 
 * ( for interop between mismatching EVT versions )
 */
export type VoidCtxLike = import("./CtxLike.ts").VoidCtxLike; // Wonder if this line also needs corrected as currently exporting  `CtxLike` as `VoidCtxLike`
export type Evt<T> = import("./Evt.ts").Evt<T>;
...

We can confirm that it is the evt module itself and not Opine through the simple example:

export { Evt } from "https://deno.land/x/evt@v1.9.11/mod.ts";

Which results in...

error: Uncaught SyntaxError: The requested module './CtxLike.ts' does not provide an export named 'CtxLike'
export { CtxLike } from "./CtxLike.ts";
~~~~~~~
    at <anonymous> (<https://deno.land/x/evt@v1.9.11/lib/types/interfaces/index.ts>:5:1)

Would you mind a raising an issue on the https://github.com/garronej/evt repo for the maintainers to fix there?

4ov commented 3 years ago

I've opened an issue garronej/evt#17 BTW i have another question, have you tried to bundle opine? I'm getting an error like

error: Uncaught ReferenceError: Cannot access 'request2' before initialization
request2.get = function get(name) {
^

Sorry for the disturbance.

cmorten commented 3 years ago

@lowray no need to apologise! πŸ˜„

Are you referring to deno bundle or deno compile? Either way do you mind opening a separate issue with the details so we track this different error there?

Thanks for raising the issue on the evt repo πŸ™‚

garronej commented 3 years ago

Thanks, @cmorten for doing the investigation work for me!

garronej commented 3 years ago

@cmorten @lowray DONE. I addressed the issue in v1.9.12 of EVT πŸŽ‰.
I would do a PR to update the lock.json but I don't know how you manage it and I am exhausted Believe it or not, it took me like 5 hours to fix this.
Supporting both older version of typescript and Deno is getting more and more challenging. πŸ˜“

cmorten commented 3 years ago

Nice one @garronej, you’re a ⭐️!

Gosh that does sounds exhausting 😞

I’ll get things sorted from this end

4ov commented 3 years ago

@garronej @cmorten i really appreciate it. thank you all β™₯️