Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot destructure property 'url' of 'nestedModules.pop(...)' as it is undefined. #218

Closed
bergercookie opened this issue Mar 28, 2021 · 6 comments
Labels
✘ bug Something isn't working

Comments

@bergercookie
Copy link

I have a file called user.ts under the api/ directory with the following contents:

import type { APIRequest } from "https://deno.land/x/aleph/types.ts";

export default function handler(req: APIRequest) {
  console.log(`req: `, req);
  console.log(`req.params: `, req.params);
  console.log(`req.params.action: `, req.params.action);
  req.status(200).json({ name: req.params.action});
}

I'm making an HTTP GET request to it using httpie

 http -v  localhost:8080/api/user action==all
GET /api/user?action=all HTTP/1.1 <--------------- Actual GET Request
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.8



HTTP/1.1 500 Internal Server Error
cache-control: max-age=0
content-length: 209
content-type: text/html; charset=utf-8
date: Sun, 28 Mar 2021 09:05:39 GMT
server: Aleph.js

<!DOCTYPE html><title>500 - internal server error</title><p><strong><code>500</code></strong><small> - </small><span>Cannot destructure property 'url' of 'nestedModules.pop(...)' as it is undefined.</span></p>

Meanwhile, I can avoid getting a 500 error, only If I put this file under api/user/[name].ts, but in this case, it bundles the last part of the url along with the parameters after ?.

➜ http -v  localhost:8080/api/user/1 action==all

GET /api/user/1?action=all HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:8080
User-Agent: HTTPie/0.9.8

HTTP/1.1 200 OK
content-length: 11
content-type: application/json; charset=utf-8
date: Sun, 28 Mar 2021 09:17:26 GMT
server: Aleph.js

{
    "name": {}
}


# Server output:
DEBUG compile '/api/user/[name].ts' in 1ms
req:  Request {}
req.params:  { name: "1action=all" }
req.params.action:  undefined

I suppose this isn't the expected behavior. Is this a bug? Am I doing something wrong?

@ije
Copy link
Member

ije commented Mar 28, 2021

this error means your api endpoint doesn't exist, i already fixed it.

ije added a commit that referenced this issue Mar 28, 2021
@bergercookie
Copy link
Author

bergercookie commented Mar 28, 2021

But my endpoint does exist since I've put a file under /api/user.ts and I'm making a request like the following: /api/user?action=all

i already fixed it.

Is it fixed? The error still persist after aleph upgrade:

14:01:20 ➜ aleph --version
aleph.js 0.3.0-alpha.20
deno 1.8.1+2f9d7c0
v8 9.0.257.3
typescript 4.2.2

EDIT: Oh, just saw the latest commit, let me re-test it.

@ije
Copy link
Member

ije commented Mar 28, 2021

oh, sorry! seems the api routing doesn't match the search ?action=all, i will fix it asap, thanks!

@ije
Copy link
Member

ije commented Mar 28, 2021

try /api/user/[action].ts instead

@ije ije added the ✘ bug Something isn't working label Mar 28, 2021
@bergercookie
Copy link
Author

try /api/user/[action].ts instead

Now, having renamed my file from user/[name].ts to user/[action.ts] when I make an HTTP request (GET /api/user/1?action=all) it still doesn't parse the parameters correctly:

INFO Server ready on http://localhost:8080/
req:  Request {}
req.params:  { action: "1action=all" }
req.params.action:  1action=all

Regarding the request GET /api/user?action=all I'm now getting an 404 instead of a 500 error like previously. But still, that's not the expected behavior. I would expect that this request would have been served by the /api/user.ts (or /api/user/index.ts) file and have the action=all be part of the req.params object.

Thanks for the quick reply and support! :)

ije added a commit that referenced this issue Mar 28, 2021
@ije
Copy link
Member

ije commented Mar 28, 2021

fixed, pls upgrade to alpha.22, thanks

@ije ije closed this as completed Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✘ bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants