Reputation: 159
I am trying to import 'setCORS' from a node module 'google-translate-api-browser' but i am getting the error SyntaxError: Unexpected token {
I already tried specifying type="module" in my main script file but it seems to have no effect.
import { setCORS } from "google-translate-api-browser";
//setting up cors-anywhere server address
const translate = setCORS("http://cors-anywhere.herokuapp.com/");
translate(original.textContent(), {to:'ne'})
.then(res => {
console.log(res.text);
})
.catch(err => {
console.log(err);
});
Upvotes: 2
Views: 159
Reputation:
Looks like you installed the module on an incorrect path..... In the command line try (make sure youre in the main parent directory):
1.rm -rf node-modules
2. npm install --save google-translate-api-browser
3. npm install
4. import the module: import {setCors} from "google-translate-api-browser"
5. Test it out
Upvotes: 1