【问题标题】:node/no-unpublished-import: "chai" is not published节点/no-unpublished-import:“chai”未发布
【发布时间】:2021-08-05 16:03:03
【问题描述】:

我的devDependencies 中有一个chai:

"devDependencies": {
    "@types/chai": "4.2.14",
    "chai": "4.2.0",
}

Chai 仅用于测试,但我不会发布测试文件。 规则node/no-unpublished-import 告诉我:

"chai" is not published 

来自文档:

这是为了防止在 npm publish 之后出现“Module Not Found”错误。 ??? 如果要导入 devDependencies,请写 .npmignore 或 package.json 的“文件”字段。

我不明白“写 .npmignore”建议是什么意思。我需要在那里写什么? 目前,我有以下内容:

.idea/

/.eslintignore
/.eslintrc.yaml
/.gitignore
/.mocharc.yaml
/.npmignore
/tsconfig.json

**.test.ts

最后一个使用 chai 忽略所有测试文件。

【问题讨论】:

    标签: node.js npm eslint chai


    【解决方案1】:

    我用的是require,但规则类似:

    .eslintrc:

    {
      "rules": {
        "node/no-unpublished-require": ["error", {"devDependencies": true}]
      }
    }
    

    【讨论】:

      【解决方案2】:

      您应该将此规则添加到.eslintrc 文件中:

          "node/no-unpublished-import": ["error", {
            "allowModules": ["chai"]
        }]
      

      【讨论】:

        猜你喜欢
        • 2021-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-12
        • 2021-09-13
        • 2017-01-16
        • 1970-01-01
        相关资源
        最近更新 更多