简体   繁体   English

在 vscode 调试器中使用 NODE_PATH

[英]Using NODE_PATH in vscode debugger

I want to auto-restart my nodeJs debugger, so I have to use Nodemon for that.我想自动重启我的 nodeJs 调试器,所以我必须使用 Nodemon。

My package.json scripts:我的package.json脚本:

"scripts": {
    "dev": "NODE_PATH=src env-cmd -f ./src/config/env/development.env nodemon ./src/app.js",
    "test": "NODE_PATH=src env-cmd -f ./src/config/env/test.env jest"
}

and here's launch.json file:这是launch.json文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/src/app.js",
            "restart": true,
            "runtimeExecutable": "nodemon"
        }
    ]
}

now after running the debugger I got the following error:现在运行调试器后出现以下错误:

Uncaught Error: Cannot find module 'config/cache'未捕获的错误:找不到模块“配置/缓存”

I guess I should tell the launch.json configuration to use NODE_PATH=src as I did in the package.json file.我想我应该告诉launch.json配置使用NODE_PATH=src ,就像我在package.json文件中所做的那样。 I'm not sure if it's the case.我不确定是不是这样。

Might be because you've set NODE_PATH to your src folder.可能是因为您已将 NODE_PATH 设置为 src 文件夹。 Try setting it to the directory that stores the node_modules folder.尝试将其设置为存储 node_modules 文件夹的目录。

Try any of the following:尝试以下任何方法:

NODE_PATH=$NODE_PATH
NODE_PATH=./node_modules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM