clutchski / coffeelint

Lint your CoffeeScript.
http://www.coffeelint.org
Other
1.18k stars 171 forks source link

node_modules not found #571

Open ABaldwinHunter opened 8 years ago

ABaldwinHunter commented 8 years ago

I'm working on a tool that runs coffeelint in a docker container.

It mounts code to lint at /code and installs node_modules the tool needs at usr/src/app/node_modules.

When we run coffeelint from the /code directory (where coffeelint.json lives), we get the following error loading the coffee-react-transform plugin:

/usr/src/app/node_modules/resolve/lib/sync.js:32
    throw new Error("Cannot find module '" + x + "' from '" + y + "'");
    ^
Error: Cannot find module 'coffee-react-transform' from '/code'
  at module.exports (/usr/src/app/node_modules/resolve/lib/sync.js:32:11)
  at /usr/src/app/node_modules/coffeelint/lib/configfinder.js:92:16
  at Array.map (native)
  at expandModuleNames (/usr/src/app/node_modules/coffeelint/lib/configfinder.js:91:53)
  at Object.exports.getConfig (/usr/src/app/node_modules/coffeelint/lib/configfinder.js:137:16)
  at getFallbackConfig (/usr/src/app/node_modules/coffeelint/lib/commandline.js:142:27)
  at lintFiles (/usr/src/app/node_modules/coffeelint/lib/commandline.js:97:38)
  at Object.<anonymous> (/usr/src/app/node_modules/coffeelint/lib/commandline.js:251:21)
  at Object.<anonymous> (/usr/src/app/node_modules/coffeelint/lib/commandline.js:256:4)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (module.js:458:32)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Module.require (module.js:468:17)
  at require (internal/module.js:20:19)
  at Object.<anonymous> (/usr/src/app/node_modules/coffeelint/bin/coffeelint:34:5)
  at Module._compile (module.js:541:32)
  at Object.Module._extensions..js (module.js:550:10)
  at Module.load (module.js:458:32)
  at tryModuleLoad (module.js:417:12)
  at Function.Module._load (module.js:409:3)
  at Module.runMain (module.js:575:10)
  at run (bootstrap_node.js:352:7)
  at startup (bootstrap_node.js:144:9)
  at bootstrap_node.js:467:3

I traced this error back to the resolve package and the way the configFinder in CoffeeLint expands modules.

Any ideas on a fix for this behavior? I notice that the version of resolve is at a little behind, and also that resolve.sync accepts a moduleDirectory option (default is node_modules), but haven't identified a solution.

Thanks for any thoughts! :) Cheers

AsaAyers commented 8 years ago

I'm not sure I follow the details, but I always recommend installing CoffeeLint and any plugins as local devDependency to whatever project you're working on.

ABaldwinHunter commented 8 years ago

@AsaAyers Thanks for the response! It looks like a workaround for our project might be to manually pass a -f config when calling the coffeelint cli to avoid going through configfinder.

The issue is that for security reasons, we don't want to install all of a project's plugins. Instead, we'd like to have some node_modules at hand at location usr/foo/node_modules preinstalled in the image, but execute the coffeelint analyze command on a separate project mounted at some directory /bar in container.

AsaAyers commented 8 years ago

CoffeeLint follows Node's resolution algorithm, which means it will walk up the tree to the root of the drive before giving up.

I think it sounds like you could solve it this way.

docker_root/
└── cccl
    ├── code
    │   ├── coffeelint.json
    │   └── other_projects_code.coffee
    ├── node_modules
    │   └── coffee-react-transform
    │       └── [ stuff that doesn't matter for this example ]
    └── package.json

cccl/package.json says you need coffee-react-transform, so it gets installed locally. Then when you mount your code at cccl/code, if it needs coffee-react-transform it will be found with the standard resolution algorithm.