InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Node.js tutorials

  • Install node.js on Ubuntu Linux
  • Install node.js on Mac
  • npm tutorial
  • Debug javascript using node and Chrome
  • Find source file location of a module
  • Find version of installed package
  • How to use pm2 to manage node.js application in production
  • NestJS Quick start tutorial on Mac
  • NextJS Quick start tutorial on Mac
  • Fix cannot find module error
 
  • Home
  • > Tutorials
  • > Web Development
  • > Node.js

node – how to fix cannot find module error

on Feb 12, 2016

Node script when run in limited environment (e.g. php exe, cron, etc.) can throw cannot find module error. The error may look like this:

throw err;    ^Error: Cannot find module 'react'    at Function.Module._resolveFilename (module.js:326:15)    at Function.Module._load (module.js:277:25)    at Module.require (module.js:354:17)    at require (internal/module.js:12:17)    at Object. (code1:1:75)    at Module._compile (module.js:398:26)    at Object.Module._extensions..js (module.js:405:10)    at Module.load (module.js:344:32)    at Function.Module._load (module.js:301:12)    at Function.Module.runMain (module.js:430:10)

To fix this set NODE_PATH environment variable before command.

$ NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules /usr/bin/node code_file.js

Suggested posts:

  1. node – how to find version of installed package
  2. bower – installation and quick start guide
  3. Python re search vs match
  4. How to prevent ssh session freezing due to timeout
  5. redis cli quick start tutorial
  6. Javascript – print all methods of an object
  7. WordPress – prevent access to php files in wp-includes
  8. React – list of all factory methods of React.DOM
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Node.js, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress