-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
vercel/next lambda fails to run minified bundle. #4327
Comments
Where can I access this Also, please try latest version of |
Just tried pastebin for alternatively you can build it yourself by cloning repo:
and the vercel/next app that I'm using to test is here: https://github.com/talmobi/vercel-next-yt-search-test The error occurs in the |
So I tried the pastebin content on command line: $ node yt-search.js
internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'cheerio'
Require stack:
- yt-search.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at o ([stdin]:1:493)
at [stdin]:1:684
at Object.1../util.js ([stdin]:6:16)
at o ([stdin]:1:633)
at r ([stdin]:1:799)
at [stdin]:1:828 {
code: 'MODULE_NOT_FOUND',
requireStack: [ 'yt-search.js' ]
} which is the same as the screenshot you've linked above. Unless I am mistaken − |
Same error being thrown with $ git clone --branch talmobi/fix/vercel-next-test https://github.com/talmobi/yt-search |
Looking inside those original input, i.e. before {
"./util.js": 2,
"async.parallellimit": undefined,
"cheerio": undefined,
"dasu": "dasu",
"fs": undefined,
"human-time": undefined,
"jsonpath": undefined,
"path": undefined,
"querystring": undefined,
"url": undefined
} I'm wondering if those should be numbers instead of |
It's the bundle of the source code but it still depends on a few dependencies such as It's not something you should be able to run from the command line directly, but be able to const yts = require( `./yt-search.js` )
... It should work, I just tried the pastebin version and it works. And to answer the The non-minified bundle works fine in vercel/next lambda, but the minified version does not. If you cloned the branch/repo you should be able to: |
The procedure you gave me isn't a step-by-step that leads to a PASS/FAIL scenario, so please bear with me while I try to understand all those words in between. I have tried the following: $ git clone https://github.com/talmobi/vercel-next-yt-search-test
$ cd vercel-next-yt-search-test
$ npm install
$ npm run build
$ npm run start
> [email protected] start vercel-next-yt-search-test
> next start
ready - started server on http://localhost:3000 After that I use a web browser to navigate to
and returns the following JSON reply: {"name":"AGA 江海迦﹣《Superman》MV"} So assuming the above is the successful case, how do I make it fail? |
... and looking at {
"_from": "github:talmobi/yt-search#talmobi/fix/vercel-next-test",
...
"main": "dist/yt-search.min.js",
...
} |
Correct, it all works locally. The issue happens when you upload this vercel/next application to vercel.com. The code inside The issue is that the hosted version fails to run the code inside the lambda function. If you use the non-minified version of the bundle ( But if you use the minifed version ( The in-depth error log is screenshotted from the vercel.com app page is on the first post of this issue (ie this one: https://i.imgur.com/2XST3ox.png ) It's a bit troublesome to test because it only fails when it's hosted on vercel, but hosting there is free. Again I'm not sure if this is an issue with how vercel/next resolves the dependencies for their lambda or an issue with uglify-js -- but the non-minified version works fine. |
Ah I see − thanks for the clarification. I'm afraid I'm out of ideas about how to reproduce this then, since I cannot access the code hosted remotely (they aren't even client-side scripts 😓) to tweak and see what works/breaks. Before I ponder further − do you upload the whole of |
The whole And because of the You should fork your own experimental branch and put your fork/branch url there instead to experiment with freely. That's the simplest way I can se right now how to do it. The latest version in that exprimental branch of the In the vercel/next app's that I've linked above that has the working version is using the non-minified version, they are just unique urls of previously deployed versions that are still alive. That being said I'll see if I can make a smaller reproducible. |
Thanks for the detailed explanation. I'm combing over the orignal and minified Meanwhile if you don't mind, please try disabling some optimisation flags to see if it makes a difference, e.g. The usual suspects I'd go for:
|
Will try to create a minimal sample repo and steps of the issue.
|
the error also persisted with or without |
That's odd, since |
Yes good catch I was editing the wrong package.json... one sec... |
-c inline=false still errors: https://vercel-next-yt-search-test-63050iwyr.vercel.app/api/hello -c collapse_vars=false still errors: https://vercel-next-yt-search-test-8c6g0ai1b.vercel.app/api/hello -c merge_vars=false still errors: https://vercel-next-yt-search-test-9nhczlhqd.vercel.app/api/hello -c reduce_vars=false still errors: https://vercel-next-yt-search-test-3m8aedoj9.vercel.app/api/hello
and just to test the non-minified version again I reuploaded and redeployed it and it's working: https://vercel-next-yt-search-test-ec3kz1q3n.vercel.app/api/hello EDIT: made the links clickable |
Thanks for all the tests! Does this vercel scenario ever work before, i.e. was there a version of |
Actually, one more test − minified but no compression:
That should be the original file with only extra whitespace and brackets removed. |
I'm not sure, I only
still the same error: https://vercel-next-yt-search-test-2clpm3fg7.vercel.app/api/hello EDIT: typo |
I see − in which case my current suspicion is that vercel may have some hard-coded pattern replacement of The original file has extra whitespace around g.ytSearch = f()
^ ^ and extra parenthesis around here: return (function(){function r(e,n,t){
^ Although there is nothing wrong with the functionality of the minified code, if vercel is looking for an exact string match, then this would explain the failure we are observing here, i.e. code only fails when hosted on their platform. |
So, is it maybe vercel's loading program's bug? Vercel looks like using this lib https://github.com/vercel/nft internally when loading libs at runtime. Should add this problem to nft's isssue? |
I'll see if I can replicate the issue on a minimal codebase with a simpler step-by-step first, I think. |
Following is simple way for using nft.
run nft print
print result
Change yt-search version
run nft print
print result
hmm, look like nothing loaded.. |
Closing since it's not an issue with |
For the sake of future duplication, share:
|
Is there no option to achieve this? just want to testing...
|
Clearly it's more than just preserving the name |
Bug report or feature request?
Bug
Uglify version (
uglifyjs -V
)3.10.2
JavaScript input
NONE
The
uglifyjs
CLI command executed orminify()
options used.uglifyjs dist/yt-search.js -cmo dist/yt-search.min.js
JavaScript output or error produced.
Vercel/next lambda is unable to resolve dependencies from a minified bundle: https://i.imgur.com/2XST3ox.png
The non-minified bundle works fine without errors inside the vercel/next lambda: https://vercel-next-yt-search-test-127g4hwhu.vercel.app/api/hello
The minified bundle loads and works fine within node itself, however.
This issue was discovered here: talmobi/yt-search#14
It is unclear if it's a vercel/next issue, or an uglify-js issue.
I've been in contact with vercel support but nothing significant has come out of it as of yet.
The text was updated successfully, but these errors were encountered: