"type": "module" import issue

Viewed 52

Using js librairies, I struggle with the fact that require and import are not suitable together. When I write "type": "module" in the package.json, then import works but require doesn't, and when I don't, the opposite happens. I don't get how to import both of the two librairies.

I import fs like this :

const fs = require('fs')

and in the other file I am importing PythonShell like this :

import { PythonShell } from 'python-shell'

Is there a way to have "type" : "module" only applying for one librairy in my package.json ? Or can I import one like the other in order to use only one key word (import or require) ?

Thank you, have a great day.

1 Answers

You don't necessarily need to use import to use the PythonShell class from python-shell, you can just use require() so your code would look like this

const fs = require('fs');
const PythonShell = require('python-shell').PythonShell;

// ...
Related