Express module not found when installed with NPM

后端 未结 14 1613
庸人自扰
庸人自扰 2020-12-22 22:59

When I try to run the app.js file created by express, I get the following error:

$ node app.js

node.js:134
        throw e; // process.nextTick         


        
14条回答
  •  盖世英雄少女心
    2020-12-22 23:19

    It appears that while npm had been updated to install global modules into /usr/local/lib/node_modules, Node's own require.paths does not yet reflect this change.

    There are two reasonable solutions:

    1. Add the following code to the top of your application:

      require.paths.push('/usr/local/lib/node_modules');
      
      • Pro: non-invasive, easy to add

      • Con: requires discipline, future versions of node will restrict access to require.paths

    2. As root, execute:

      ln -s /usr/local/lib/node_modules /usr/local/lib/node
      
      • Pro: reasonably non-invasive

      • Con: requires root, modifies linux fs, might not survive system updates

提交回复
热议问题