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 find module dasu #14

Open
Cammoy opened this issue Jul 15, 2020 · 14 comments
Open

Cannot find module dasu #14

Cammoy opened this issue Jul 15, 2020 · 14 comments
Labels
invalid? This doesn't seem right solved should be fixed, waiting for user to acknowledge and close

Comments

@Cammoy
Copy link

Cammoy commented Jul 15, 2020

Hi, I am experiencing an issue on vercel where it says in cannot find module dasu, I normally works locally. So it does not make sense. I am thinking its something to do the how that module is packaged.

Do you have any ideas?

@Cammoy Cammoy changed the title Cannot Cannot find module dasu Jul 15, 2020
@Cammoy
Copy link
Author

Cammoy commented Jul 15, 2020

I will re try this on vercel now and let you know

@talmobi
Copy link
Owner

talmobi commented Jul 15, 2020

Halåj~

Which version are you using and which npm and node versions?

@talmobi
Copy link
Owner

talmobi commented Jul 24, 2020

Was this issue resolved?

@talmobi talmobi closed this as completed Jul 26, 2020
@yareyaredesuyo
Copy link

I also got this error, when I used this library in next.js api and deploy it to vercel.
But works fine in local.

error:

2020-11-26T14:40:11.999Z	abf48a97-dc8e-41ac-8d19-1a45a4f3f425	
ERROR	Error: Cannot find module 'dasu'Require 
stack:- /var/task/node_modules/yt-search/dist/yt-search.min.js
- /var/task/.next/serverless/pages/api/youtubesingle.js
- /var/task/now__launcher.js
- /var/runtime/UserFunction.js
- /var/runtime/index.js    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:831:15)   
 at Function.Module._load (internal/modules/cjs/loader.js:687:27)   
 at Module.require (internal/modules/cjs/loader.js:903:19)    at require (internal/modules/cjs/helpers.js:74:18)   
 at s (/var/task/node_modules/yt-search/dist/yt-search.min.js:1:386)  
 at /var/task/node_modules/yt-search/dist/yt-search.min.js:1:560   
 at Object.1../util.js (/var/task/node_modules/yt-search/dist/yt-search.min.js:1:986)  
 at s (/var/task/node_modules/yt-search/dist/yt-search.min.js:1:526)   
 at r (/var/task/node_modules/yt-search/dist/yt-search.min.js:1:684)   
 at /var/task/node_modules/yt-search/dist/yt-search.min.js:1:701 {  code: 'MODULE_NOT_FOUND',

version:

"yt-search": "^2.5.0",

@talmobi talmobi reopened this Nov 26, 2020
@talmobi talmobi self-assigned this Nov 26, 2020
@talmobi
Copy link
Owner

talmobi commented Nov 26, 2020

Can you show the context of where it's being used in the code?

@yareyaredesuyo
Copy link

yareyaredesuyo commented Nov 26, 2020

I use this library in the following way in nextjs lambda api.

pages/api/yt.ts

const yts = require("yt-search");

import { NextApiRequest, NextApiResponse } from 'next'

export default async (req: NextApiRequest, res: NextApiResponse) => {

  const {
    query: { q },
  } = req;

  try {
    const r = await yts(q);
    res.status(200).json(r.videos);
  } catch (e) {
    console.log(e);
  }
}

@talmobi
Copy link
Owner

talmobi commented Nov 27, 2020

Thanks~

I can reproduce the issue, I'm looking into it.

@talmobi
Copy link
Owner

talmobi commented Nov 27, 2020

Update:

I haven't solved the issue yet, but it seems to be related to the lambda api is installed in vercel/next.

Even though vercel/next claims the lambdas use the package-json.lock and npm it is still failing to resolve the dependencies. I'm not sure if they are not downloaded at all or if it's a problem in how they resolve the dependencies.

Usually lamdas load all their data from a zip file direclty. But given that they apparently support npm modules and pacakge.json's they may be doing some tricky things behind the scenes that are failing. It is unclear as of yet.

The static pre-fetching works fine as you can see here: https://vercel-next-yt-search-test-hcxf6c9i7.vercel.app ( youtube video title inserted dynamically below the header )

@talmobi talmobi added the invalid? This doesn't seem right label Nov 27, 2020
@talmobi
Copy link
Owner

talmobi commented Nov 29, 2020

Update2:

I've been in contact with vercel support and trying to resolve the issue.

As a side note, here's an example of using yt-search in aws lambda: https://github.com/talmobi/yt-search-lambda

example api url: https://69v539djw3.execute-api.us-east-1.amazonaws.com/default/yt-search-api-lambda?search=superman+theme

@yareyaredesuyo
Copy link

@talmobi Thanks a lot!!!

@yareyaredesuyo
Copy link

I investigated the problem, and I found that changing package.json's main target from dist/yt-search.min.js to dist/yt-search.js and it worked.

Maybe related to uglify.js setting problem?

following is working image.

スクリーンショット 2020-11-30 19 11 10

@talmobi
Copy link
Owner

talmobi commented Nov 30, 2020

@yareyaredesuyo wow! you're right! I can reproduce that it's working with the non-minified version (example: https://vercel-next-yt-search-test-127g4hwhu.vercel.app/api/hello).

Not sure what's going on but looks like perhaps uglifyJS is doing something that prevents the vercel/next lambda loader from recognizing or loading modules properly. Or something like that.

Not sure if it's an issue with uglifyJS or the vercel/next lambda loader.

Not sure what to do about it yet.

Nice catch!

@talmobi talmobi added the bug Something isn't working label Nov 30, 2020
@talmobi
Copy link
Owner

talmobi commented Nov 30, 2020

I'm leaning towards simply skipping the minified version altogether, regardless if it's an issue with uglify-js or vercel/next.

Thoughts or suggestions?

@yareyaredesuyo

@yareyaredesuyo
Copy link

yareyaredesuyo commented Dec 1, 2020

I think, if you want to deliver both versions, you should set not minified version for main, and minified version for another (like setting jsdelivr). And this is very standard way, because it's a bit hard for debugging minified libs and tracking errors.

Sample implementation:
https://github.com/axios/axios/blob/master/package.json

"main": "index.js",
"jsdelivr": "dist/axios.min.js",
"unpkg": "dist/axios.min.js",

And I think this is very tiny lib, not so much need for uglifying (also uglify is a bit obsolated, and you should think about switching using library like terser, ncc. switching example: twbs/bootstrap#27813).

refs:

https://stackoverflow.com/questions/48673408/should-javascript-npm-packages-be-minified

talmobi added a commit that referenced this issue Dec 2, 2020
affect some third-party module resolution strategies. ref:
#14

problem: the uglify-js minified bundle seems to prevent some third-party
module detection/resolution from working properly. Particularly vercel
and its lambda loader. see: #14

solution: use non-minified bundle instead. Size difference is negligible
as this is a backend/server-side bundle and it will help out with debugging also.
@talmobi talmobi removed the bug Something isn't working label Feb 7, 2021
@talmobi talmobi added the solved should be fixed, waiting for user to acknowledge and close label Oct 4, 2021
@talmobi talmobi removed their assignment Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid? This doesn't seem right solved should be fixed, waiting for user to acknowledge and close
Projects
None yet
Development

No branches or pull requests

3 participants