'"type": "module" import issue
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.
Solution 1:[1]
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;
// ...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SkwalExe |