Skip to content

Commit

Permalink
docs: improve failed-to-load-textlints-module.md (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
azu authored Feb 25, 2023
1 parent 15ca439 commit d97af3d
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ The way of configuration is same with textlint-rule.
}
```

Put the config of `textlint-rule-foo` rule in `text-rule-preset-bar` rule-preset.
Put the config of `foo` rule in `text-rule-preset-example` rule-preset.

```json
```json5
{
"rules": {
"preset-example": {
"foo": true // configuration for "textlint-rule-foo"
"foo": true // configuration for "textlint-rule-foo" in "textlint-rule-preset-bar"
}
}
}
Expand Down
54 changes: 44 additions & 10 deletions docs/faq/failed-to-load-textlints-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
> Failed to load textlint's plugin module: "html" is not found.
## Solution A
## Reason

Maybe, you have installed `textlint` and rules into different place.
You may have installed `textlint` and the rule/preset/plugin in different places.

- If you have installed `textlint` as `--global`(`-g`), must install each rule as `--global`.
- If you have installed `textlint` as `--save-dev`(`-D`), must install each rule as `--save-dev`.
`textlint` can not found the rule/preset/plugin package in different place.

## Solution B
## Solution A: Install `textlint` and the rule/preset/plugin in the same place

1. Update `textlint` and the rule and preset, plugin.
2. Check your `.textlintrc.json` option value.
- If you have installed `textlint` as `--global`(`-g`), you must install each rule as `npm install --global <rule-package>`.
- If you have installed `textlint` as `--save-dev`(`-D`), you must install each rule as `npm install --save-dev <rule-package>`.

## Solution B: Check the rule name in `.textlintrc.json`

1. Update `textlint` and the rule/preset/plugin.
2. Check your `.textlintrc.json`'s "rules" section.

**1**: This error is caused by mismatch between `textlint` and the other(rule and preset, plugin).

**2**: This error is caused by invalid config value.

- Check the rule name in `.textlintrc.json` and `package.json`
Check the rule name in `.textlintrc.json` and `package.json`

**rule**

In the following case, you have to installed `textlint-rule-foo` module via `npm install textlint-rule-foo`.
When `textlint-rule-foo` module is missing in `node_modules`, textlint throw this error.

```json
{
Expand All @@ -36,6 +45,31 @@ Maybe, you have installed `textlint` and rules into different place.
}
```

In the cause, have to installed `textlint-rule-foo` module via `npm install textlint-rule-foo`.
**preset**

In the following case, you have to installed `textlint-rule-preset-foo` module via `npm install textlint-rule-preset-foo`.
When `textlint-rule-preset-foo` module is missing in `node_modules`, textlint throw this error.

```json
{
"rules": {
"preset-foo" : true
}
}
```

If you want to configure the rule in the preset, you can write the following config.

```json
{
"rules": {
"preset-foo" : {
"<rule-name>": {
"key": "value"
}
}
}
}
```

When the module is missing in `node_modules`, textlint throw this error.
See also [Configuring textlint](../configuring.md).
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"preset-abc": true
}
}
33 changes: 33 additions & 0 deletions packages/@textlint/config-loader/test/snapshots/preset/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"ok": true,
"config": {
"rules": [
{
"type": "RuleInPreset",
"ruleId": "abc/a",
"options": true,
"filePath": "<MODULES_DIR>/textlint-rule-preset-abc/index.js",
"moduleName": "<MODULES_DIR>/textlint-rule-preset-abc",
"ruleKey": "a"
},
{
"type": "RuleInPreset",
"ruleId": "abc/b",
"options": true,
"filePath": "<MODULES_DIR>/textlint-rule-preset-abc/index.js",
"moduleName": "<MODULES_DIR>/textlint-rule-preset-abc",
"ruleKey": "b"
},
{
"type": "RuleInPreset",
"ruleId": "abc/c",
"options": true,
"filePath": "<MODULES_DIR>/textlint-rule-preset-abc/index.js",
"moduleName": "<MODULES_DIR>/textlint-rule-preset-abc",
"ruleKey": "c"
}
],
"plugins": [],
"filterRules": []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
"preset-abc": true,
"abc/a": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ok": false,
"error": {
"message": "Can not load rule",
"errors": [
"Failed to load textlint's rule module: \"abc/a\" is not found.\nSee FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md\n"
]
}
}

0 comments on commit d97af3d

Please sign in to comment.