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

Error unable to load module 'url' #195

Closed
bw-sonph opened this issue Feb 23, 2024 · 6 comments
Closed

Error unable to load module 'url' #195

bw-sonph opened this issue Feb 23, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@bw-sonph
Copy link

Currently I use esbuild to build the main.js file, however it seems the url module is not supported and an error appears as below. Please help.

Response
{
"errorType": "ReferenceError",
"errorMessage": "Error resolving module 'url' from '/var/task/dist/main.js'",
"stackTrace": [
""
]
}

@richarddavison
Copy link
Contributor

URL is available on global scope. Do you have problems with a dependency or in your own code?

@bw-sonph
Copy link
Author

I have a test.ts file

import url from 'node:url'

export const handler = async (event: any, context: any) => {
   const adr = 'http://localhost:8080/default.htm?year=2017&month=february';
   const q = url.parse(adr, true);

   console.log(q);
};

when using the command below

esbuild test.ts --platform=node --target=es2020 --outdir=dist --format=esm --bundle --minify --external:@aws-sdk --external:uuid 

to build into a test.js file with the following content

import o from"url";var c=async(r,a)=>{let t=o.parse("http://localhost:8080/default.htm?year=2017&month=february",!0); console.log(t)};export{c as handler};

Then deploy to the lambda with Runtime = Amazon Linux 2023 and the boostrap file is llrt-lambda-x64.zip
Screenshot 2024-02-24 at 9 46 00

then get the following error

Screenshot 2024-02-24 at 9 46 14
{
   "errorType": "ReferenceError",
   "errorMessage": "Error resolving module 'url' from '/var/task/index.mjs'",
   "stackTrace": [
     ""
   ]
}

It seems the module 'url' cannot be loaded.

@richarddavison
Copy link
Contributor

I see. You can use new URL(adr) instead without importing anything 👍

@bw-sonph
Copy link
Author

Thank you for your help.
Actually I'm building a lambda using nestjs. Build successfully and run in lambda but get the same error.

{
   "errorType": "ReferenceError",
   "errorMessage": "Error resolving module 'url' from '/var/task/index.mjs'",
   "stackTrace": [
     ""
   ]
}

@richarddavison
Copy link
Contributor

Ah right, we probably need to add it as a module.

@richarddavison richarddavison added the enhancement New feature or request label Feb 26, 2024
@imaitland imaitland mentioned this issue Feb 28, 2024
@richarddavison
Copy link
Contributor

richarddavison commented Mar 7, 2024

Tracked by: #214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants