Cannot find module 'acorn/acorn'

2,268 views
Skip to first unread message

Andy Lee

unread,
Dec 8, 2014, 12:20:09 AM12/8/14
to tern...@googlegroups.com
'm running Windows 7 and I want to use Tern in Emacs, but when I activate tern mode it gives me this error:


Request failed: (:failed . Could not start Tern server

module.js:340
    throw err;
          ^
Error: Cannot find module 'acorn/acorn'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at exports.toString (c:\Users\[myusername]\AppData\Roaming\.emacs.d\el-get\tern\lib\infer.js:17:25)
    at Object.<anonymous> (c:\Users\[myusername]\AppData\Roaming\.emacs.d\el-get\tern\lib\infer.js:22:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
)

I know acorn is another Node.js module, so I installed it via npm. But tern still cannot find acorn module.
Where should I put acorn module? I've tried copy acorn next to tern directory, put it under tern directory, and every sub-directory of tern directory, but none of them works.

Andy Lee

unread,
Dec 8, 2014, 9:51:19 AM12/8/14
to tern...@googlegroups.com
After reading this article http://www.bennadel.com/blog/2169-where-does-node-js-and-require-look-for-modules.htm
regarding to how require() function in Node.js works. I figure out that I didn't setup NODE_PATH environment variable.
setting up NODE_PATH solved my problem.

To setup NODE_PATH in emacs init.el, add this:
(setenv "NODE_PATH" "C:/node/node_modules")

Marijn Haverbeke

unread,
Dec 9, 2014, 9:51:02 AM12/9/14
to Andy Lee, tern-dev
The idiomatic way to install npm modules is locally, not system-wide
(going into tern's directory and saying `npm install`). That way you
won't even need NODE_PATH and you are less likely to run into version
conflicts.
> --
> You received this message because you are subscribed to the Google Groups
> "tern-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tern-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages