Closed 4ov closed 3 years ago
Hi @lowray 👋
So the first error you've reported appears to be a bug with deno bundle
as far as I can see, the outputted, bundled js file appears to have placed the definition of:
request2.get = ...
on line 309, when in fact request2
is only defined later on line 23284. Hence why we get the reference error.
If you have a use-case for Opine in this bundled form then I would recommend raising an issue to report the bug with deno bundle
on the main https://github.com/denoland/deno repo 😄.
...interestingly if you fix the request2
issue by moving the request2.get
method to the appropriate place, then you receive the following error:
error: Uncaught ReferenceError: init is not defined
await init(read("./pkg/denoflate_bg.wasm"));
^
at file:///~/git/asos-craigmorten/opine/opine.js:18261:1
So I sense there may be a few (or perhaps the same?) bugs with the deno bundle
CLI command at the moment. This particular one is regarding a missing init
method which is completely missing from the bundle, indicating that deno bundle
is somehow missing the default export
/ import
of this method within the https://github.com/hazae41/denoflate library which Opine makes use of.
The error you are seeing when not providing the --no-check
is due to deno bundle
stripping all type information from Opine to create your opine.js
file. Without this type information Deno is unable to infer some of the properties on the app
object, nor will it know what types the req
and res
objects have. You would either need to import the Opine types into your file and manually type the various objects, or alternatively, don't use typescript at all by changing your file extension to .js
, i.e. serve.js
- given you are making use of --no-check
which skips typechecking, it may be simpler for you to just use plain JavaScript in the first place!
Ultimately the errors you are seeing are expected behaviour when importing objects and functions from a JS file into a TS file / project.
Given neither of these issues are (afaik) anything wrong with Opine itself I will close this - happy to re-open if something else comes to light!
Having a read, I believe this will all be fixed in a next release following the merge of https://github.com/denoland/deno/pull/8901 which upgrades swc which is used for bundling. So probably not worth raising a new issue as likely a duplicate of all the listed ones.
Issue
Setup:
I'm receiving an error when i try to use a bundled version of opine
Details
I'm trying to use a bundled version of opine to avoid errors with #97 (
deno bundle https://deno.land/x/opine@1.0.0/mod.ts
) the bundle generated successfully but when i try to use this bundle like :I'm getting this error
without --no-check :