【问题标题】:The requested module 'franc' does not provide an export named 'default'请求的模块“franc”不提供名为“default”的导出
【发布时间】:2021-11-07 19:21:03
【问题描述】:

我正在尝试使用 franc 包,但每次我尝试运行它时都会出现此错误“请求的模块 'franc' 不提供名为 'default' 的导出”,我不知道这意味着什么。我尝试将文件名更改为 mjs 或在 package.json 中添加“type”="module" 但这只会给我这个错误,我在网上找不到任何解决方案。

注意:--experimental-modules 不起作用(它说 '\302\226 npm': command not found)

这是js文件(我在package.json中添加了“type”="module")

import franc from 'franc';
console.log(franc('Hi, I speak english!'));

这是 package.json

{
  "name": "curs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "franc": "^6.0.0",
    "lang": "^0.1.1"
  }
  
}

PS:忽略 lang 我的意思是首先让法郎运行。

【问题讨论】:

    标签: javascript node.js json github npm


    【解决方案1】:

    这意味着该包没有像export default ... 这样的导出,但您正尝试像它一样导入它。实际上,当您提供的名称不带花括号时,这意味着您要导入默认导出并为其命名。

    您尝试导入的库实际上有一个类似export function franc() { //... } 的导出,因此您需要像这样导入它:

    import { franc } from 'franc';
    

    【讨论】:

    • 感谢这实际上帮助了我。我几天前才开始学习 node.js,看来我正在学习的课程有点过时了。
    • 很高兴它有帮助!
    猜你喜欢
    • 1970-01-01
    • 2021-11-02
    • 2022-01-25
    • 2022-11-16
    • 2023-02-02
    • 2021-10-03
    • 1970-01-01
    • 2019-10-06
    • 2019-08-31
    相关资源
    最近更新 更多