I want to use this module in my nodejs app.
the issue is I used a lot of modules with require
statement before, like:
const translate = require('google-translate-open-api');
Now when i want to use the mentioned module using this:
import { HttpProxyAgent } from 'http-proxy-agent';
I get this error:
SyntaxError: Cannot use import statement outside a module
if I use this code to import the module:
const { HttpProxyAgent }= require('http-proxy-agent');
I get this error:
TypeError: createHttpProxyAgent is not a function
How can I use this kind of modules in nodejs app?
2
Answers
Simply wrap
HttpProxyAgent
inside{}
just like theimport
one.in your package.json file add:
and then use:
you might also need to make changes in other imports which use require keyword.