alephjs / aleph.js

The Full-stack Framework in Deno.
https://aleph.deno.dev/
MIT License
5.26k stars 168 forks source link

Unable to use UUID v4 from deno standard library in ssr definition #413

Open tatemz opened 3 years ago

tatemz commented 3 years ago

The following ssr definition fails when building an aleph application

import { SSROptions } from "https://deno.land/x/aleph@v0.3.0-beta.19/types.d.ts";
import { v4 } from "https://deno.land/std@0.109.0/uuid/mod.ts";

type Props = {
  uuid: string | undefined;
};

export const ssr: SSROptions<Props> = {
  props: (request) => {
    const uuid = request.params["uuid"];

    return {
      uuid: v4.validate(uuid) ? uuid : undefined,
    };
  },
};

The following error log is output.

 > src/.aleph/production/pages/index.bundling.js:1:19: error: Could not read from file: /foobar/src/.aleph/production/-/deno.land/std@0.109.0/uuid/mod.bundling.js
    1 │ import { v4 } from "../../../-/deno.land/std@0.109.0/uuid/mod.bundling.js";
      ╵                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 > src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:367:4: error: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
    367 │     async *iterate() {
        ╵     ~~~~~

 > src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:4005:73: error: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
    4005 │ var AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function*() {
         ╵                                                                          ~~~~~

 > src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:6408:0: error: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
    6408 │ async function* fromReadable(val) {
         ╵ ~~~~~

 > src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:6414:12: error: Transforming for-await loops to the configured target environment ("es2015") is not supported yet
    6414 │         for await (const chunk of iterable){
         ╵             ~~~~~

error: Uncaught (in promise) Error: Build failed with 5 errors:
src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:367:4: error: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:4005:73: error: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:6408:0: error: Transforming async generator functions to the configured target environment ("es2015") is not supported yet
src/.aleph/production/-/cdn.esm.sh/v53/deno_std_node_stream.bundling.js:6414:12: error: Transforming for-await loops to the configured target environment ("es2015") is not supported yet
src/.aleph/production/pages/index.bundling.js:1:19: error: Could not read from file: /foobar/src/.aleph/production/-/deno.land/std@0.109.0/uuid/mod.bundling.js
  let error = new Error(`${text}${summary}`);
              ^
    at failureErrorWithLog (https://deno.land/x/esbuild@v0.13.2/mod.js:1439:15)
    at https://deno.land/x/esbuild@v0.13.2/mod.js:1097:28
    at runOnEndCallbacks (https://deno.land/x/esbuild@v0.13.2/mod.js:885:63)
    at buildResponseToResult (https://deno.land/x/esbuild@v0.13.2/mod.js:1095:7)
    at https://deno.land/x/esbuild@v0.13.2/mod.js:1204:14
    at https://deno.land/x/esbuild@v0.13.2/mod.js:573:9
    at handleIncomingPacket (https://deno.land/x/esbuild@v0.13.2/mod.js:670:9)
    at readFromStdout (https://deno.land/x/esbuild@v0.13.2/mod.js:540:7)
    at https://deno.land/x/esbuild@v0.13.2/mod.js:1709:11
make: *** [prod] Error 1
tatemz commented 3 years ago

Maybe this is not an error specific to https://deno.land/std@0.109.0/uuid/mod.ts. 🤷 I'll keep debugging.

Possibly related to #411

hsjoberg commented 3 years ago

I'm also seeing this error when trying to import date-fns and react-qr-svg.

Not sure what the deno.js file isn't respected? I have this deno.js file:

{
  "compilerOptions": {
    "target": "esnext",
    "lib": ["dom", "dom.iterable", "dom.asynciterable", "deno.ns", "deno.unstable"]
  }
}
ije commented 3 years ago

@tatemz please try to update the default (es2015) build target to es2018 or higher since the esbuild can't transform the async generator expression, i will improve the error outputting

ije commented 3 years ago

FYI https://github.com/alephjs/aleph.js/blob/ac6ca05e600f72aa741ee952ab2ce1df663ede18/types.d.ts#L182