Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Cannot find module 'lint' (with global remark-lint install) #115

Closed
brettz9 opened this issue Oct 3, 2016 · 19 comments
Closed

Cannot find module 'lint' (with global remark-lint install) #115

brettz9 opened this issue Oct 3, 2016 · 19 comments
Assignees
Labels

Comments

@brettz9
Copy link

brettz9 commented Oct 3, 2016

Using Atom 1.10.2 and remark-lint installed globally, I'm getting "Cannot find module 'lint'" with the following .remarkrc:

{
    "plugins": {
        "lint": {
            "list-item-indent": "space"
        }
    }
}
@wooorm
Copy link
Contributor

wooorm commented Oct 23, 2016

Hi, thanks for raising this!

I did some investigation today, and you’re right: globally installed remark-lints are not loaded when inside Atom.

So the thing is, to find globally installed modules, load-plugin looks where npm modules are installed to, which varies greatly across OSes, or if someone’s using something like nvm. This works pretty good.

Now, Atom/Electron need to do funky stuff. So they ship their own version of npm, which is configured to install global modules in /Applications/Atom.app/Contents/Frameworks/Atom Helper.app/Contents/lib/node_modules (in my case).

And load-plugin picks up that path. This is kinda weird, as Atom is hiding info explicitly, so I’m not sure working around that would be feasible.

Anyway, for now you cannot use global plugins in atom, unfortunately.
I raised an issue on npm-prefix: eush77/npm-prefix#1, but I’m unsure it should be changed.

@wooorm
Copy link
Contributor

wooorm commented Oct 23, 2016

Oh and you can also set a prefix to your global npm modules, in an .npmrc file: https://docs.npmjs.com/files/npmrc

@oupala
Copy link

oupala commented Feb 20, 2017

It seems that I have the same problem as @brettz9.

I'm using Atom on linux and I'm also using nvm. My globally installed node modules path is then a bit strange:

/home/<user>/.nvm/versions/node/v<version>/lib/node_modules/

This makes the right path hard to guess unless you know which version of node to use (and hence which node_module directory to consider).

I have globally installed remark-lint and remark-preset-lint-recommended but when I launch Atom with a simple markdown file and the same .remarkrc file as @brettz9, I get the following error

Error: Cannot find module `lint`at line 0 col 0
    at /home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/file-pipeline/configure.js:68:19
    at /home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:444:7
    at Array.forEach (native)
    at /home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:443:13
    at /home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:327:5
    at /home/<user>/.atom/packages/linter-markdown/node_modules/vfile-find-up/index.js:135:9
    at FSReqWrap.oncomplete (fs.js:123:15)

With no .remarkrc at all, the plugin seems to work correctly, but I cannot then configure the plugin which makes it unusable for me as the default config does not fit my needs.

@wooorm
Copy link
Contributor

wooorm commented Feb 20, 2017

@oupala Did you see my previous comment? nvm is fine, but Atom explicitly hides the info we need from us, and we can’t easily get around it (eush77/npm-prefix#1).

For now the solution is to use locally installed modules!

@oupala
Copy link

oupala commented Feb 20, 2017

Yes, I've read your comment.

How can I install the modules locally? What do you mean by locally? And what modules are necessary?

@wooorm
Copy link
Contributor

wooorm commented Feb 20, 2017

The normal behaviour, npm install remark-lint (without -g), installs packages locally.

The modules you need to install, differ based on your .remarkrc. In your case, you mentioned remark-lint and remark-preset-lint-recommended, so probably those!

@oupala
Copy link

oupala commented Feb 20, 2017

It is a pain to use, but the workaround works...

When you use markdown on a lot of repos, it just don't make it to install packages locally on every repo (especially when they are not managed by npm).

I hope that the upstream bug will be fixed as soon as possible!

@oupala
Copy link

oupala commented Feb 27, 2017

Just to check, when you say locally, you mean: in the same directory as the markdown files are stored?

@wooorm
Copy link
Contributor

wooorm commented Feb 27, 2017

In the directory of your .remarkrc file!

@oupala
Copy link

oupala commented Mar 15, 2017

I tried to install the following npm packages locally (where the markdown files are stored):

  • remark-preset-lint-recommended
  • remark-preset-lint-consistent

I added a .remarkrc file locally (where the markdown files are stored):

{
  "presets": [
    "lint-recommended",
    "lint-consistent"
  ],
  "plugins": {
    "lint": {
      "list-item-indent": "mixed",
      "table-cell-padding": "false"
    }
  }
}

I have the following atom packages installed:

  • linter 2.1.0
  • linter-markdown 3.1.0

And when I open a markdown file, here is the error that appears in the linter ui:

TypeError: name.indexOf is not a function at resolvePlugin (/home/<user>/.atom/packages/linter-markdown/node_modules/load-plugin/index.js:59:12) at merge (/home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:105:20) at required (/home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:266:3) at preset (/home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:169:5) at merge (/home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:81:11) at required (/home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:266:3) at /home/<user>/.atom/packages/linter-markdown/node_modules/unified-engine/lib/configuration.js:315:9 at /home/<user>/.atom/packages/linter-markdown/node_modules/vfile-find-up/index.js:135:9 at FSReqWrap.oncomplete (fs.js:123:15)

I can't succeed to make the markdown linter to work! Please help if you understand something in my mess...

wooorm added a commit that referenced this issue Apr 14, 2017
@wooorm
Copy link
Contributor

wooorm commented Jul 8, 2017

I just pushed better support for global modules, but it probably requires some set-up on your part.
I added docs on how to do that in the soon-to-be readme.

Hope this helps, cheers,
Titus

@oupala
Copy link

oupala commented Jul 11, 2017

Thanks a lot @wooorm for this update. Do we have to update linter-markdown on our side? If yes, could you tell us when the new release of linter-markdown will be available on Atom's repo?

@wooorm
Copy link
Contributor

wooorm commented Jul 11, 2017

GH-143 only adds docs for this feature, as the feature was implemented a level deeper (in load-plugin). To get the new version, you can uninstall and reinstall linter-markdown, and follow the docs that will be added in GH-143.

@oupala
Copy link

oupala commented Jul 11, 2017

It seems to work well, but I had to install everything locally.

Is there a way to install and configure the linter user-wide so I get the same configuration for all the markdown files I'm editing?

@wooorm
Copy link
Contributor

wooorm commented Jul 11, 2017

If you are using a .remarkrc, you need to install your plugins locally or globally. You can add .remarkrc files to your home directory for them to take effect.

@oupala
Copy link

oupala commented May 16, 2018

I still find it difficult to lint my markdown files with a user-wide configuration.

Here's what I've done:

  • I have a .remarkrc file in /home/user/.remarkrc
  • I'm using nvm and I have globally installed remark-preset-lint-recommended and remark-preset-lint-consistent by npm install -g remark-preset-lint-recommended remark-preset-lint-consistent
  • my markdown files are in /home/user/mydocs/example.md

As my .remarkrc file is the following:

{
  "plugins": [
    "remark-preset-lint-recommended",
    ["remark-lint-list-item-indent", "space"],
    "remark-preset-lint-consistent"
  ]
}

then I also need to install remark-lint-list-item-indent globally by npm install -g remark-lint-list-item-indent

  • and finally, I have the linter-markdown plugin installed in Atom

Do you think it is a right guide of enabling this feature?

@jmatsushita
Copy link

@oupala If I follow exactly these steps I get:

Error: Could not find module remark-preset-lint-recommended at addModule...

Does it work for you?

@oupala
Copy link

oupala commented Jun 22, 2018

@jmatsushita Here is what I have installed:

  • Atom 1.27.2 x64
  • Atom modules
    • linter 2.2.0
    • linter-markdown 5.2.2
    • linter-ui-default 1.7.1
  • inside ~/.nvm/versions/node/v8.11.2/lib/node_modules (as I'm using nvm)
    • remark-cli
    • remark-frontmatter
    • remark-lint-list-item-indent
    • remark-lint-table-cell-padding
    • remark-preset-lint-consistent
    • remark-preset-lint-recommended

And everything work (except the fact that I can disable a rule enabled by a preset see issue #156 that you created).

I don't really want to uninstall everything just to try to install it again. I'm afraid of not being able to install it again and make it work.

@jmatsushita
Copy link

I applied this workaround #156 (comment) from @wooorm and it solved the rule disabling as well as the Could not find module remark-preset-lint-recommended error. 👻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants