Nodejs Cannot find module

前端 未结 5 469
南旧
南旧 2020-12-30 00:40

I\'m getting an error when trying to use any global module, exemple:

Error: Cannot find module \'express\'
    at Function.Module._resolveFilename (module.js:         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-30 01:02

    I'm working in Linux, but when I require express, I'm doing so with a relative path to where it is installed and it works fine:

    var express = require('./public/node_modules/express');
    

    I'm sure the same thing would work with a windows path as well. If you want to be more explicit and declare an absolute path, that would be the nuclear option to make sure you always know exactly where your module is being loaded from regardless of where your scripts are being run from.

    If you still have a problem after using an explicit path, I don't know what the problem might be. . .

提交回复
热议问题