Unable to add new dependency in react application

Viewed 427

I have a react application. I added a new dependency to it. Here are the details:

Dependency: curlconverter

Link: https://github.com/NickCarneiro/curlconverter

command: npm install --save curlconverter

Now I am accessing this in my react codebase. Here is the snippet:

import './App.css';
import IntervalHookCounter from './counter.js';

import { toJsonString } from 'curlconverter';

let foobar  = () => {
    let x = toJsonString("curl 'http://en.wikipedia.org/' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Referer: http://www.wikipedia.org/' -H 'Cookie: GeoIP=US:Albuquerque:35.1241:-106.7675:v4; uls-previous-languages=%5B%22en%22%5D; mediaWiki.user.sessionId=VaHaeVW3m0ymvx9kacwshZIDkv8zgF9y; centralnotice_buckets_by_campaign=%7B%22C14_enUS_dsk_lw_FR%22%3A%7B%22val%22%3A%220%22%2C%22start%22%3A1412172000%2C%22end%22%3A1422576000%7D%2C%22C14_en5C_dec_dsk_FR%22%3A%7B%22val%22%3A3%2C%22start%22%3A1417514400%2C%22end%22%3A1425290400%7D%2C%22C14_en5C_bkup_dsk_FR%22%3A%7B%22val%22%3A1%2C%22start%22%3A1417428000%2C%22end%22%3A1425290400%7D%7D; centralnotice_bannercount_fr12=22; centralnotice_bannercount_fr12-wait=14' -H 'Connection: keep-alive' --compressed");
    console.log(x)
}

function App() {
  foobar()
  return (
    <IntervalHookCounter />
  );
}

export default App;

on running the project I am getting the following error:

./node_modules/curlconverter/node_modules/yargs/lib/platform-shims/esm.mjs 16:41
Module parse failed: Unexpected token (16:41)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| const REQUIRE_ERROR = 'require is not supported by ESM';
| const REQUIRE_DIRECTORY_ERROR = 'loading a directory of commands is not supported yet for ESM';
> const mainFilename = fileURLToPath(import.meta.url).split('node_modules')[0];
| 
| const __dirname = fileURLToPath(import.meta.url);

I also tried replacing import import { toJsonString } from 'curlconverter'; with var curlconverter = require('curlconverter'); and then using curlconverter.toJsonString({...}), still facing same error.

Any help will be appreciated.

1 Answers

This an open issue in curlconverter package. use version - 3.12 to avoid error

npm install --save curlconverter@3.12

Recommended: remove all node_modules and reinstall

Related