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

not support CommonJS #7

Closed
theazran opened this issue May 15, 2023 · 4 comments
Closed

not support CommonJS #7

theazran opened this issue May 15, 2023 · 4 comments

Comments

@theazran
Copy link

/home/runner/bard/index.js:1
const Bard = require('googlebard')
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/bard/node_modules/googlebard/dist/index.js from /home/runner/bard/index.js not supported.
Instead change the require of /home/runner/bard/node_modules/googlebard/dist/index.js in /home/runner/bard/index.js to a dynamic import() which is available in all CommonJS modules.
at Object. (/home/runner/bard/index.js:1:14) {
code: 'ERR_REQUIRE_ESM'
}

@LautaroFranc
Copy link

what is the solution?

@tockawaffle
Copy link

You can use a dynamic import, if import("..") doesn't work for you:

const importDynamic = new Function('modulePath', 'return import(modulePath)')

And then use it in a async function, like so:

async function main() {
    const importDynamic = new Function('modulePath', 'return import(modulePath)')
    const {Bard} = await importDynamic("googlebard")
}

@mashwishi
Copy link

mashwishi commented May 17, 2023

I hope this help!

let cookies = process.env.BARD_COOKIES;

let importDynamic = new Function('modulePath', 'return import(modulePath)')
const { Bard } = await importDynamic("googlebard")

let bot = new Bard(cookies);

let response = await bot.ask(messageContent, conversationID);

@theazran
Copy link
Author

I hope this help!

let cookies = process.env.BARD_COOKIES;

let importDynamic = new Function('modulePath', 'return import(modulePath)')
const { Bard } = await importDynamic("googlebard")

let bot = new Bard(cookies);

let response = await bot.ask(messageContent, conversationID);

Thanks, solved

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

No branches or pull requests

4 participants