Unknown Error of using 'watchify' npm package

I used the code
const ytdl = require('ytdl-core');
const search = require('yt-search');
const { getInfo, play, showInfo } = require('./helper.js');

// Get HTML elements
const searchResult = document.getElementsByClassName('result');
const searchInput = document.getElementById('searchInput');

// Do all the functions
searchInput.addEventListener('keyup', async (ev) => {
let results = await getInfo(searchInput);

await showInfo(results);
});
const ytdl = require('ytdl-core');
const search = require('yt-search');
const { getInfo, play, showInfo } = require('./helper.js');

// Get HTML elements
const searchResult = document.getElementsByClassName('result');
const searchInput = document.getElementById('searchInput');

// Do all the functions
searchInput.addEventListener('keyup', async (ev) => {
let results = await getInfo(searchInput);

await showInfo(results);
});
and got this error in the browser console (see the img) I'm using watchify npm package to convert it to something that browser understands. and I got this error when I used this code. idk why this error came. I even put "type": "module", in the package.json file and put type="module" in the <script> tag in the html file
19 Replies
Melodium
Melodium2y ago
anyone please :(
Jochem
Jochem2y ago
gotta be patient, people will answer when they can also, calling attention to your thread is against the rules
Melodium
Melodium2y ago
ik, but i have less time to finish my project, i had no choice sry
Jochem
Jochem2y ago
best bet I have is deleting node_modules and running npm install . Make a backup of node_modules if you don't trust just straight up deleting it, or you changed anything in there (which you shouldn't do)
Melodium
Melodium2y ago
i installed only one package lol *two
Jochem
Jochem2y ago
I have no other advice to give you, so good luck then
Melodium
Melodium2y ago
ok I did what you said, but it returns the same err what the heck is even util.js, and why doesn't the npm add it
vince
vince2y ago
Last time yt-search was updated was 2 years ago according to the github And it looks like the issue is that your yt-search package is calling some file util.js I did a quick search and didn't find much; their github has 1 closed issue from 2 years ago. My recommendation is making a youtube video parser from scratch I'd be really surprised if youtube didn't have some public api for this https://developers.google.com/youtube/v3/docs/videos You could also probably just use any package or the default http/https api from node to get youtube videos PROBABLY
const axios = require('axios');

// https://www.youtube.com/results?search_query=cat+videos
const searchTerms = 'cat+videos';
const videoList = axios.get(`https://www.youtube.com/results?search_query=${searchTerms}`);
const axios = require('axios');

// https://www.youtube.com/results?search_query=cat+videos
const searchTerms = 'cat+videos';
const videoList = axios.get(`https://www.youtube.com/results?search_query=${searchTerms}`);
I'd have to see what exactly videoList returns, but that or looking at the youtube api link I sent would probably be a decent start So I just tested the axios method, it only returns the html, so yea you'd have to go with the youtube api method unless you want to manually parse the html for each link
Melodium
Melodium2y ago
i copy pasted the code from github for the util.js, which fixed that error, but new errors are popping up :(
vince
vince2y ago
Just remove the package and make your own at this point it seems unmaintained
Melodium
Melodium2y ago
f-, watchify returns an error which is hard to resolve
arseError: 'import' and 'export' may appear only with 'sourceType: module'
arseError: 'import' and 'export' may appear only with 'sourceType: module'
is the error
13eck
13eck2y ago
And I think that this here is your problem: you're copying code from github without knowing what it does or how it works. Not sure if you've heard of the "X/Y Problem" but this smells of it. You're so hyper-focused on fixing what you don't understand that you're not asking the right questions. You came here to fix a specific error from a random github repo that hasn't been updated in years. Instead, you should read #How To Ask Good Questions and ask the question you're trying to accomplish. Don't ask, "how do I fix this error?" Ask, "I'm trying to do [thing], and have tried [approach] and [other approach] and it's not doing [what I want]. Help?"
Melodium
Melodium2y ago
I've removed it, and a new error came related to watchify, and idfk how I can fix it. I can understand what the error is btw watchify is also an npm package but now I get an error which's from watchify (browserify) saying that SyntaxError: 'import' and 'export' may appear only with 'sourceType: module' i wanna make a search mechanism where the results show when you search for a track in the search input so i used browserify npm package to convert node.js code into browser understandable code instead of doing what i expected, it keeps on returning the same error I googled almost like 50-60 times but can't get a clear answer everyone posted the solution that suits their code and not my code im using yt-search and ytdl-core for this
ErickO
ErickO2y ago
a single google search lead me to this https://github.com/mattdesl/esmify
GitHub
GitHub - mattdesl/esmify: parse and handle import/export for browse...
parse and handle import/export for browserify. Contribute to mattdesl/esmify development by creating an account on GitHub.
Melodium
Melodium2y ago
huh? what did u search
ErickO
ErickO2y ago
literally the error
Melodium
Melodium2y ago
bruh i searched it.. wait dumb me, i use brave search instead of google also should we install esmify package?
ErickO
ErickO2y ago
the readme tells you what to do I've never used it nor have I used browserify so I wouldn't know
Melodium
Melodium2y ago
first, i need to go eat and come so that i can focus clearly thanks for the help bro! still that returns a new error SyntaxError: D:\Visual Studio Code\IT exhibition\node_modules\htmlparser2\lib\esm\index.js: Export namespace should be first transformed by @babel/plugin-proposal-export-namespace-from.