'node/no-unpublished-import: "chai" is not published

I have a chai among my devDependencies:

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

Chai is requires for tests only, but I don't going to publish the test files. The rule node/no-unpublished-import tells me:

"chai" is not published 

From the documentation:

This intends to prevent "Module Not Found" error after npm publish. 💡 If you want to import devDependencies, please write .npmignore or "files" field of package.json.

I did not understand what means "write .npmignore" advice. What I need to write there? Currently, I have below content:

.idea/

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

**.test.ts

The last one ignores all test files using chai.



Solution 1:[1]

I'm using require, but the rules are similar:

.eslintrc:

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

Solution 2:[2]

You should add this rule to the .eslintrc file:

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

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 woofdinos
Solution 2 Murat Colyaran