remarkjs / remark-lint

plugins to check (lint) markdown code style
https://remark.js.org
MIT License
947 stars 130 forks source link

remark cannot find globally installed presets #199

Closed Kristinita closed 5 years ago

Kristinita commented 5 years ago

#165 — possibly related issue.

1. Summary

I don't understand, how I can use globally installed remark plugins. Variant from documentation doesn't work for me.

2. Argumentation

I want to use remark not only for JavaScript projects. I can use remark for projects in another programming languages and just for my notes. I don't think, that adding many node_modules for each project is a good idea.

3. Data

No locally installed remark plugins.

* Kira

[Goddess][]
plugins:
  preset-lint-recommended:

4. Steps to reproduce

5. Expected behavior

User can use only .remarkrc.yaml configuration file → all globally installed plugins will work.

6. Actual behavior

D:\SashaDebugging>remark KiraRemark.md
KiraRemark.md
  1:1  error  Error: Could not find module `preset-lint-recommended`
    at addModule (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:242:27)
    at use (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:203:7)
    at addIn (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:197:7)
    at addPreset (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:166:9)
    at merge (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:150:5)
    at Config.create (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:105:5)
    at done (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\find-up.js:148:20)
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:54:3)

× 1 error

I try:

Same error.

7. Environment

Thanks.

wooorm commented 5 years ago

Super weird! This should not be like the issue you mentioned: one preset should work fine globally. If the readme example doesn’t work, I’m thinking that this is related to your environment. Maybe a Windows issue?

What happens if you try remark KiraRemark.md --use remark-preset-lint-recommended (no config file?).

Could you provide a list of globally installed packages, so I can debug?

Kristinita commented 5 years ago

@woorm,

1. nodeenv

I can't reproduce the problem, use nodeenv:

D:\SashaDebugging>nodeenv kira_remark_env
 * Install prebuilt node (11.9.0) ….. done.
symbolic link created for kira_remark_env\Scripts\nodejs.exe <<===>> node.exe
 * Install npm.js (latest) …

D:\SashaDebugging>"kira_remark_env/Scripts/activate.bat"
(kira_remark_env) D:\SashaDebugging>npm install --global remark-cli remark-preset-lint-recommended
D:\SashaDebugging\kira_remark_env\Scripts\remark -> D:\SashaDebugging\kira_remark_env\Scripts\node_modules\remark-cli\cli.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\remark-cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ remark-preset-lint-recommended@3.0.2
+ remark-cli@6.0.1
added 287 packages from 196 contributors in 87.392s

(kira_remark_env) D:\SashaDebugging>remark KiraRemark.md
-   Kira

[Goddess][]
KiraRemark.md
       1:1  warning  Missing newline character at end of file  final-newline            remark-lint
       1:3  warning  Incorrect list-item indent: add 2 spaces  list-item-indent         remark-lint
  3:1-3:12  warning  Found reference to undefined definition   no-undefined-references  remark-lint

‼ 3 warnings

2. Usage without config

Same error:

D:\SashaDebugging>remark KiraRemark.md --use remark-preset-lint-recommended
KiraRemark.md
  1:1  error  Error: Could not find module `preset-lint-recommended`
    at addModule (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:242:27)
    at use (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:203:7)
    at addIn (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:197:7)
    at addPreset (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:166:9)
    at merge (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:150:5)
    at Config.create (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\configuration.js:105:5)
    at done (C:\Users\SashaChernykh\AppData\Roaming\npm\node_modules\remark-cli\node_modules\unified-engine\lib\find-up.js:148:20)
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:54:3)

× 1 error

3. List of global packages

npm list -g --depth 0 > Kira_nodejs__global_packages_list.txt
C:\Users\SashaChernykh\AppData\Roaming\npm
+-- @commitlint/config-conventional@6.1.3
+-- @commitlint/prompt@6.1.3
+-- @commitlint/prompt-cli@6.1.3
+-- @prettier/plugin-python@0.0.0-development (github:prettier/plugin-python#0aa2517f4d22f55f8c4f5a7d2c6c3caaa807503c)
+-- align-yaml@0.1.8
+-- autoprefixer-stylus@0.14.0
+-- bower@1.8.8
+-- breakdance-cli@1.0.1
+-- browser-sync@2.26.3
+-- cash@0.8.0
+-- cash-global@0.2.0
+-- chalk@1.1.3
+-- clean-console@0.4.0
+-- clean-css-cli@4.2.1
+-- coffee-script@1.12.7
+-- coffeelint@2.1.0
+-- commitizen@2.10.1
+-- commitlint@6.2.0
+-- conventional-changelog-cli@1.3.22
+-- css-to-stylus-converter@1.1.9
+-- csslint@1.0.5
+-- csslint-cli@1.0.5
+-- cssnano@3.10.0
+-- cz-conventional-changelog@2.1.0
+-- cz-emoji@1.1.2
+-- depcheck@0.6.11
+-- eclint@2.8.1
+-- eslint@4.19.1
+-- exec-extra@2.8.0
+-- extract-zip@1.6.7
+-- eyo@4.2.0
+-- fixmyjs@1.0.3
+-- generate@0.14.0
+-- generate-changelog@1.7.1
+-- generate-package@0.7.3
+-- giflossy@3.0.41
+-- glob-run@0.1.6
+-- grunt@1.0.3
+-- grunt-cli@1.3.2
+-- grunt-init@0.3.2
+-- hjson@3.1.2
+-- hpm-cli@2.0.1
+-- html-minifier@3.5.21
+-- htmllint-cli@0.0.7
+-- imagemin-cli@4.0.0
+-- joblint@2.3.2
+-- js-beautify@1.8.9
+-- js2coffee@2.2.0
+-- jshint@2.10.1
+-- json2yaml@1.1.0
+-- json5@1.0.1
+-- json5-validator@0.2.0
+-- jsonlint@1.6.3
+-- jsonlint-cli@1.0.1
+-- license-generator@0.0.13
+-- localtunnel@1.9.1
+-- markdown-to-restructuredtext@2.0.1
+-- markdownlint@0.8.1
+-- markdownlint-cli@0.13.0
+-- markmon@0.0.7
+-- minjson@0.0.2
+-- modclean@2.1.2
+-- ngrok@2.3.0
+-- nib@1.1.2
+-- npm@6.7.0
+-- npm-check@5.9.0
+-- npm-check-updates@2.15.0
+-- npm-install-missing@0.1.4
+-- pageres-cli@4.1.0
+-- parallel@1.2.0
+-- parallelshell@3.0.2
+-- posthtml-cli@0.3.2
+-- purify-css@1.2.6
+-- release-it@7.6.3
+-- remark-cli@6.0.1
+-- remark-preset-lint-markdown-style-guide@2.1.2
+-- remark-preset-lint-recommended@3.0.2
+-- shields-badge-url-custom@1.0.0
+-- string-similarity@1.2.2
+-- stylelint@9.10.1
+-- stylint@1.5.9
+-- stylus@0.54.5
+-- stylus-supremacy@2.12.7
+-- svgo@1.1.1
+-- textr-cli@0.4.0
+-- toml-checker@0.1.3
+-- travis-lint@1.0.0
+-- tslint@5.12.1
+-- typescript@2.9.2
+-- typograf-cli@4.1.0
+-- typographic-ellipses@1.0.11
+-- typographic-math-symbols@1.1.5
+-- uglify-js@3.4.9
+-- uglifycss@0.0.28
+-- write-good@0.10.3
+-- yaml2json@1.0.2
+-- yamljs@0.3.0
+-- yaspeller@5.0.1
`-- yml-sorter@1.1.1

Thanks.

wooorm commented 5 years ago

Wait, so your first example (### 1. nodeenv) shows that with a config file, it works? But when passing a plugin in with --use doesn’t?

What happens if you use nodeenv with the second example? (### 2. Usage without config)

kortina commented 5 years ago

I am trying similarly to use remark with a global install and it cannot find any plugins, even though I have indeed installed them.

npm list -g | grep remark
├─┬ remark@10.0.1
│ ├─┬ remark-parse@6.0.3
│ ├─┬ remark-stringify@6.0.4
├─┬ remark-cli@6.0.1
│ ├─┬ remark@10.0.1
│ │ ├─┬ remark-parse@6.0.3
│ │ ├─┬ remark-stringify@6.0.4
├─┬ remark-lint@6.0.4
│ └─┬ remark-message-control@4.1.1
├─┬ remark-preset-lint-markdown-style-guide@2.1.2
│ ├─┬ remark-lint@6.0.4
│ │ └─┬ remark-message-control@4.1.1
│ ├─┬ remark-lint-blockquote-indentation@1.0.2
│ ├─┬ remark-lint-code-block-style@1.0.2
│ ├─┬ remark-lint-definition-case@1.0.3
│ ├─┬ remark-lint-definition-spacing@1.0.3
│ ├─┬ remark-lint-emphasis-marker@1.0.2
│ ├─┬ remark-lint-fenced-code-flag@1.0.2
│ ├─┬ remark-lint-fenced-code-marker@1.0.2
│ ├─┬ remark-lint-file-extension@1.0.2
│ ├─┬ remark-lint-final-definition@1.0.2
│ ├─┬ remark-lint-hard-break-spaces@1.0.3
│ ├─┬ remark-lint-heading-increment@1.0.2
│ ├─┬ remark-lint-heading-style@1.0.2
│ ├─┬ remark-lint-link-title-style@1.0.3
│ ├─┬ remark-lint-list-item-content-indent@1.0.2
│ ├─┬ remark-lint-list-item-indent@1.0.3
│ ├─┬ remark-lint-list-item-spacing@1.1.2
│ ├─┬ remark-lint-maximum-heading-length@1.0.2
│ ├─┬ remark-lint-maximum-line-length@1.2.0
│ ├─┬ remark-lint-no-auto-link-without-protocol@1.0.2
│ ├─┬ remark-lint-no-blockquote-without-marker@2.0.2
│ ├─┬ remark-lint-no-consecutive-blank-lines@1.0.2
│ ├─┬ remark-lint-no-duplicate-headings@1.0.2
│ ├─┬ remark-lint-no-emphasis-as-heading@1.0.2
│ ├─┬ remark-lint-no-file-name-articles@1.0.2
│ ├─┬ remark-lint-no-file-name-consecutive-dashes@1.0.2
│ ├─┬ remark-lint-no-file-name-irregular-characters@1.0.2
│ ├─┬ remark-lint-no-file-name-mixed-case@1.0.2
│ ├─┬ remark-lint-no-file-name-outer-dashes@1.0.3
│ ├─┬ remark-lint-no-heading-punctuation@1.0.2
│ ├─┬ remark-lint-no-inline-padding@1.0.3
│ ├─┬ remark-lint-no-literal-urls@1.0.2
│ ├─┬ remark-lint-no-multiple-toplevel-headings@1.0.2
│ ├─┬ remark-lint-no-shell-dollars@1.0.2
│ ├─┬ remark-lint-no-shortcut-reference-image@1.0.2
│ ├─┬ remark-lint-no-shortcut-reference-link@1.0.3
│ ├─┬ remark-lint-no-table-indentation@1.0.3
│ ├─┬ remark-lint-ordered-list-marker-style@1.0.2
│ ├─┬ remark-lint-ordered-list-marker-value@1.0.2
│ ├─┬ remark-lint-rule-style@1.0.2
│ ├─┬ remark-lint-strong-marker@1.0.2
│ ├─┬ remark-lint-table-cell-padding@1.0.3
│ ├─┬ remark-lint-table-pipe-alignment@1.0.2
│ ├─┬ remark-lint-table-pipes@1.0.2
│ └─┬ remark-lint-unordered-list-marker-style@1.0.2
├─┬ remark-reference-links@4.0.3
│ │ ├─┬ remark@10.0.1
│ │ │ ├─┬ remark-parse@6.0.3
│ │ │ ├─┬ remark-stringify@6.0.4

.remarkrc:

  "plugins": [
    "remark-reference-links",
    "remark-lint"
  ]
}

Error:


DEBUG="*" remark _posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md -u reference-links
  unified-engine:configuration Looking for `.remarkrc,.remarkrc.js,.remarkrc.yml,.remarkrc.yaml` configuration files +0ms
  unified-engine:configuration Looking for `remarkConfig` fields in `package.json` files +3ms
  unified-engine:find-up No files found for `/Users/kortina/src/kortina.github.io/_posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md` +0ms
  unified-engine:file-set-pipeline:stdin Ignoring `streamIn` +0ms
  unified-engine:file-pipeline:read Reading `/Users/kortina/src/kortina.github.io/_posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md` in `utf8` +0ms
  unified-engine:file-pipeline:read Read `/Users/kortina/src/kortina.github.io/_posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md` (err: null) +4ms
  unified-engine:find-up Read file `/Users/kortina/src/kortina.github.io/.remarkrc` +10ms
  unified-engine:file-pipeline:configure Using settings `{}` +0ms
  unified-engine:file-pipeline:configure Using `3` plugins +0ms
  unified-engine:file-pipeline:configure Using plug-in `fail`, with options `undefined` +0ms
  unified-engine:file-pipeline:configure Using plug-in `fail`, with options `undefined` +0ms
  unified-engine:file-pipeline:configure Using plug-in `fail`, with options `undefined` +0ms
  unified-engine:file-pipeline:parse Parsing `_posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md` +0ms
  unified-engine:file-pipeline:queue Queueing `_posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md` +0ms
  unified-engine:file-pipeline:queue Flushing: all files can be flushed +0ms
  unified-engine:file-pipeline:stringify Not compiling failed document +0ms
  unified-engine:file-pipeline:copy Not copying +0ms
  unified-engine:file-pipeline:stdout Ignoring writing to `streamOut` +0ms
  unified-engine:file-pipeline:file-system Ignoring writing to file-system +0ms
_posts/2019-02-07-napkin-modeling-the-us-govt-p-l.md
  1:1  error  Error: Could not find module `remark-reference-links`
    at addModule (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:242:27)
    at use (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:203:7)
    at addEach (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:188:9)
    at addPreset (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:164:9)
    at merge (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:150:5)
    at Config.create (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:105:5)
    at done (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/find-up.js:148:20)
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

✖ 1 error```
kortina commented 5 years ago

I was just testing on another machine, from a fresh start, and I followed the README exactly and ran into similar issue.

From instructions via: https://github.com/remarkjs/remark/blob/master/doc/getting-started.md

$ npm install --global remark-cli remark-html remark-preset-lint-markdown-style-guide
$ echo "_Hello_." > readme.md # create the example file from the instructions
$ remark readme.md --use html --use preset-lint-markdown-style-guide
readme.md
  1:1  error  Error: Could not find module `html`
    at addModule (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:242:27)
    at use (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:203:7)
    at addIn (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:197:7)
    at addPreset (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:166:9)
    at merge (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:150:5)
    at Config.create (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:108:3)
    at done (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/configuration.js:78:25)
    at apply (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/find-up.js:185:7)
    at applyAll (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/find-up.js:175:7)
    at found (/usr/local/lib/node_modules/remark-cli/node_modules/unified-engine/lib/find-up.js:167:7)

✖ 1 error

Anyone got ideas on the root cause here?

wooorm commented 5 years ago

@kortina Could you run your last example again with DEBUG="*" before it, and post the results?

kortina commented 5 years ago

I tracked down the issue. There was a probably where I didn't have nodenv correctly prepended to my path, but I did have the nodenv binary on my path, so I think there was some sort of mismatch.

Once I added the following to my ~/.bash_profile and reinstalled, things worked as expected:

export PATH="$HOME/.nodenv/bin:$PATH"
wooorm commented 5 years ago

Oh good find! Alright, I’m guessing something similar is also the problem for @Kristinita: I think making sure the modules are somewhere in your path will fix it!

bdlangton commented 5 years ago

I had the same issue, but a different solution, so I just wanted to post here in case others see this.

I am on Mac. I didn't have $NODE_PATH set, so I had to add this: export NODE_PATH="/usr/local/lib/node_modules"

That fixed it. I added it to to my .zshrc file.