“类型”:“模块”导入问题

发布于 2025-01-28 14:45:03 字数 363 浏览 2 评论 0原文

使用JS图书馆,我为需要和进口的事实而苦苦挣扎。当我在软件包中编写“ type”:“模块”时,json,然后导入但不需要,而当我不这样做时,情况恰恰相反。我没有如何导入两个库中的两个。

我会导入这样的fs:

const fs = require('fs')

在另一个文件中,我正在以这样的方式导入pythonshell:

import { PythonShell } from 'python-shell'

有没有办法让“ type”:“模块”仅适用于我的软件包中的一个库。还是我可以像另一个一样导入一个关键词(导入或需要)?

谢谢你, 祝你有美好的一天。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2025-02-04 14:45:03

您不一定需要使用导入来使用python-shell的pythonshell类,您可以只使用require() ,因此您的代码看起来像这样

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

// ...

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;

// ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文