alephjs / aleph.js

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

Bundler attemps incorrect download link when running in production #418

Open tiptenbrink opened 2 years ago

tiptenbrink commented 2 years ago
❯ aleph start
INFO Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
WARN Download https://deno.land/x/zod@v3.9.8/index.ts/external.ts failed, retrying...
error: Uncaught (in promise) Error: Can't compile module '/pages/index.tsx': Can't compile module '/components/deployContent.tsx': Can't compile module '/components/deployable.tsx': Can't compile module '/lib/runInfo.ts': Can't compile module '/api/deploy/runs.ts': Can't compile module 'https://deno.land/x/zod@v3.9.8/mod.ts': Not Found
  /** create bundle chunk. */
  ^
    at Bundler.compile (https://deno.land/x/aleph@v0.3.0-beta.19/bundler/mod.ts:245:3)
    at async https://deno.land/x/aleph@v0.3.0-beta.19/bundler/mod.ts:301:23
    at async Promise.all (index 0)
    at async Bundler.bundleChunk (https://deno.land/x/aleph@v0.3.0-beta.19/bundler/mod.ts:292:26)
    at async Bundler.bundle (https://deno.land/x/aleph@v0.3.0-beta.19/bundler/mod.ts:136:11)
    at async Aleph.#bundle (https://deno.land/x/aleph@v0.3.0-beta.19/server/aleph.ts:1488:5)
    at async Aleph.#init (https://deno.land/x/aleph@v0.3.0-beta.19/server/aleph.ts:262:7)
    at async serve (https://deno.land/x/aleph@v0.3.0-beta.19/server/server.ts:355:3)
    at async https://deno.land/x/aleph@v0.3.0-beta.19/commands/start.ts:45:2

This is an error in my current project.

This only happens when running in production mode, not when using aleph dev. It seems like it incorrectly generated the URL to download, because if you look at the index.ts it is simply importing external.ts, there is no such thing as a index.ts directory in the module.

I'm quite sure my imports are fine:

runs.ts:

import { z } from 'zod'

import_map.json

{
  "imports": {
    "~/": "./",
    "aleph/": "https://deno.land/x/aleph@v0.3.0-beta.19/",
    "aleph/types": "https://deno.land/x/aleph@v0.3.0-beta.19/types.d.ts",
    "aleph/web": "https://deno.land/x/aleph@v0.3.0-beta.19/framework/core/mod.ts",
    "aleph/react": "https://deno.land/x/aleph@v0.3.0-beta.19/framework/react/mod.ts",
    "react": "https://esm.sh/react@17.0.2",
    "react-dom": "https://esm.sh/react-dom@17.0.2",
    "base64url": "https://deno.land/std@0.110.0/encoding/base64url.ts",
    "path": "https://deno.land/std@0.110.0/path/mod.ts",
    "octokitRequest": "https://cdn.skypack.dev/@octokit/request@5.6.2",
    "zod": "https://deno.land/x/zod@v3.9.8/mod.ts"
  },
  "scopes": {}
}
tiptenbrink commented 2 years ago

I've done some more digging, it seems to be caused by the following part in the [index.ts](https://deno.land/x/zod@v3.9.8/index.ts) of zod:

import * as z from "./external.ts";
export * from "./external.ts";
export { z };

Probably the double export (which in a way export the same thing) confuses Aleph.js's bundler. I made a test repo with a working refactor of the zod contents here to illustrate the issue.

ije commented 2 years ago

@tiptenbrink thanks, i will look into it

hiraginoyuki commented 2 years ago

I was concerned about the same issue, so I tried to find the cause. And I think these lines are suspicious (although I'm not sure): https://github.com/alephjs/aleph.js/blob/93ff6f078e3c5f54db6082452e1da12cf7b02026/bundler/mod.ts#L173-L181 I will do further investigations.

P.S. In my case, the path of dependencies in https://deno.land/std@0.115.0/path/mod.ts was somehow transformed to something like https://deno.land/std@0.115.0/path/mod.ts/common.ts, which is wrong.