InfoHeap
Tech tutorials, tips, tools and more
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 source file location of a module
  2. How to install node (node.js) on Mac
  3. Debug javascript using node-inspector, node-debug, nodemon and Chrome
  4. node – how to find version of installed package
  5. How to install node.js on Ubuntu Linux
  6. How to use pm2 to manage node.js application in production
  7. node-sass quick start tutorial on Linux and Mac
  8. Javascript – print all methods of an object
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 | 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

Copyright © 2023 InfoHeap.

Powered by WordPress