Closed brunohafonso closed 1 year ago
What code are you trying to execute?
i got the same error just trying a simple code like this in typescript
import { searchMusics } from "node-youtube-music";
searchMusics("Hello").then((musics) => {
console.log(musics);
});
What's your set up? How can I reproduce?
nothing crazy out here, just a fresh project, i uploaded to github here https://github.com/gloirekiba/groove-tube
just run npm run dev
This lib is an ES Module, so try to run it with tsnd-esm
instead of tsnd
. Would that fix the issue?
Same to me. I'm using CommonJS in my tsconfig.json
configuration:
{
"compilerOptions": {
"suppressImplicitAnyIndexErrors": true,
"noImplicitAny": false,
"noImplicitThis": false,
"strictNullChecks": false,
"allowSyntheticDefaultImports": true,
"declaration": true,
"module": "CommonJS",
"target": "es5",
"sourceMap": true,
"outDir": "dist",
"esModuleInterop": true
},
"include": [
"src/**/*"
]
}
Try to call a method that will produce the error.
import { searchMusics } from "node-youtube-music";
searchMusics("Hello").then((musics) => {
console.log(musics);
});
Solution: To import an ES module in CommonJS, you can use the import() function with a dynamic import statement.
const music = await import('node-youtube-music')
const r = await music.searchMusics(q)
Another workaround I tried is to use version 0.7.0
Error [ERR_REQUIRE_ESM]: require() of ES Module D:\Projects\sangeet-discordbot\node_modules\got\dist\source\index.js from D:\Projects\sangeet-discordbot\node_modules\node-youtube-music\dist\index.js not supported.
I am trying to run .ts file and I get this error.
For now I am switching back to older version as a workaround.
Hey guys, read this: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#pure-esm-package
It 100% applies to node-youtube-music.
Using the latest version of the package
0.10.2