[英]Error: Cannot find module 'pg', after running npm install pg
Using VSCode.使用 VSCode。 Installed latest Node.js (first time user) for Windows, and the desired modules, one of which was 'pg' (npm install pg)
为 Windows 安装了最新的 Node.js(首次用户)和所需的模块,其中一个是“pg”(npm install pg)
At the top of my script I have this: const pg = require('pg');
在我的脚本顶部我有这个:
const pg = require('pg');
When i attempt to debug, I get this error when it hits that line:当我尝试调试时,遇到该行时出现此错误:
Exception has occurred: Error
Error: Cannot find module 'pg'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (c:\EBI\Work\Node-pg-log\get_pg_log.js:3:12)
at Module._compile (module.js:649:14)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Is there something else I need to install or set up?我还需要安装或设置其他东西吗? Debugging is in place.
调试到位。
This usually happens when node_modules/
folder is located in some sub-directory.这通常发生在
node_modules/
文件夹位于某个子目录中时。 Like喜欢
/app
----index.js
----/libs
--------/node_modules/
You want a directory structure like你想要一个目录结构,比如
/app
----index.js
----node_modules/
Where node_modules
folder is either in the current directory or in some upper level directory其中
node_modules
文件夹位于当前目录或某个上层目录中
If you are using TypeScript it is necessary to install pg types.如果您使用的是 TypeScript 则需要安装 pg 类型。 Use the command
使用命令
npm install --save-dev @types/pg
The above answer on directory structure doesn't seem to apply to my case.上面关于目录结构的答案似乎不适用于我的情况。 My directory structure has /node_modules in the same directory as /app.
我的目录结构在与 /app 相同的目录中有 /node_modules。 Any other ideas on how to resolve this issue?
关于如何解决此问题的任何其他想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.