微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NodeJS / NPM / node-gyc / make - 有些东西不起作用,无法安装 npm 模块 mdns

如何解决NodeJS / NPM / node-gyc / make - 有些东西不起作用,无法安装 npm 模块 mdns

我知道其他人已经问过这个问题,我已经尝试了这些解决方案,但仍然无法解决。这让我可以根据自己的情况提供更多详细信息。

认为这是某种编译或构建工具的问题,我认为是 node-gyc 还是 Make?

运行 npm install 会抛出一页又一页的错误。 运行 npm install mdns 也会引发错误页面

我想这可能是由于操作系统附带的 NodeJS 版本而发生的某种奇怪的事情。我之前尝试删除 Node、NPM、NVM 等,但似乎无法真正删除 NodeJS。我的意思是,我进去删除了我能找到的所有对节点的引用,但我仍然看到它在 node --version 上给我输出,所以现在谁知道呢。我认为这是发布这个问题并看看其他人的想法的好点。

如果我必须完全消灭 NodeJS、NPM、NVM 等。从一开始我就觉得很酷。事实上,我更喜欢我认为的,只是为了有信心知道我正在运行全新安装。

详情如下:

- Debian 10
- Running on a Beaglebone Green Wireless (armv7)
- Freshly flashed image of bone-emmC-flasher-debian-10.3-iot-armhf-2020-04-06-4gb.img - which is debian 10.3
- ~# lsb_release -a
    No LSB modules are available.
    distributor ID: Debian
    Description:    Debian GNU/Linux 10 (buster)
    Release:        10
    Codename:       buster

- ~# nvm --version
    0.38.0
- ~# node --version
    v14.17.3
- ~# npm --version
    6.14.13
- ~# make --version
    GNU Make 4.2.1
    Built for arm-unkNown-linux-gnueabihf

- npm -- version
    {
        projectP: '1.0.0',npm: '6.14.13',ares: '1.17.1',brotli: '1.0.9',cldr: '39.0',icu: '69.1',llhttp: '2.1.3',modules: '83',napi: '8',nghttp2: '1.42.0',node: '14.17.3',openssl: '1.1.1k',tz: '2021a',unicode: '13.0',uv: '1.41.0',v8: '8.4.371.23-node.67',zlib: '1.2.11'
    }

除了缺少模块之外,启动 NodeJS 应用程序似乎没问题...

root@bgw00000000:~/projectP# npm start

> projectP@1.0.0 start /root/projectP
> export $(cat .env | xargs) && nodemon main.js

[nodemon] 1.19.4
[nodemon] to restart at any time,enter `rs`
[nodemon] watching dir(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node main.js`
internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'mdns'
Require stack:
- /root/projectP/service-mdns.js
- /root/projectP/main.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/root/projectP/service-mdns.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/root/projectP/main.js:10:29)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14) {
  code: 'MODULE_NOT_FOUND',requireStack: [ '/root/projectP/service-mdns.js','/root/projectP/main.js' ]
}
[nodemon] app crashed - waiting for file changes before starting...

service-mdns.js 的第 2 行是有问题的行:

// import the modules
const mdns = require('mdns')            < -------- This one here
const io = require('socket.io-client')

export class MulticastDNSService {...}

它在我的 package.json 中

root@bgw00000000:~/projectP# cat package.json 
{
  "name": "projectP","version": "1.0.0","description": "projectP","main": "main.js","repository": {
    "type": "git","url": "git+ssh://git@gitlab.com/<username>/projectP.git"
  },"dependencies": {
    "bluebird": "^3.5.1","body-parser": "^1.18.2","bonescript": "^0.7.4-beta1","cors": "^2.8.5","dotenv": "^4.0.0","express": "^4.16.2","mdns": "^2.5.1",<-------It's here,and it works on my MacOS just fine.
    "moment": "^2.24.0","node-fetch": "^2.6.1","pm2": "^4.2.1","ramda": "^0.17.1","request-promise": "^2.0.1","socket.io": "^2.3.0","socket.io-client": "^2.3.0","sqlite3": "^5.0.2","uuid": "^8.3.1"
  },"optionalDependencies": {
    "fsevents": "^2.3.2"
  },"devDependencies": {
    "nodemon": "^1.7.3"
  },"keywords": [],"author": "John","license": "MIT","bugs": {
    "url": "https://gitlab.com/<username>/projectP/issues"
  },"homepage": "https://gitlab.com/<username>/projectP#readme","scripts": {
    "start": "export $(cat .env | xargs) && nodemon main.js","tracewarnings": "export $(cat .env | xargs) && node --trace-warnings main.js","startpm2": "pm2 start main.js","restartpm2": "pm2 restart all"
  }
}
root@bgw00000000:~/projectP# 

所以我在最简单的环境中调查了这个问题:

root@bgw00000000:~/temp# npm init
[...removed...all default values for the init....]
root@bgw00000000:~/temp# npm install mdns

> mdns@2.7.2 install /root/temp/node_modules/mdns
> node-gyp rebuild

make: Entering directory '/root/temp/node_modules/mdns/build'
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o
In file included from ../src/dns_sd.cpp:1:
../src/mdns.hpp:32:10: Fatal error: dns_sd.h: No such file or directory
 #include <dns_sd.h>
          ^~~~~~~~~~
compilation terminated.
make: *** [dns_sd_bindings.target.mk:177: Release/obj.target/dns_sd_bindings/src/dns_sd.o] Error 1
make: Leaving directory '/root/temp/node_modules/mdns/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` Failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:375:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Linux 4.19.94-ti-r42
gyp ERR! command "/root/.nvm/versions/node/v14.17.3/bin/node" "/root/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/temp/node_modules/mdns
gyp ERR! node -v v14.17.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN temp@1.0.0 No description
npm WARN temp@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mdns@2.7.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mdns@2.7.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2021-07-16T18_18_45_365Z-debug.log

我抓取了/root/.npm/_logs/2021-07-16T18_18_45_365Z-debug.log:

root@bgw00000000:~/temp# cat /root/.npm/_logs/2021-07-16T18_18_45_365Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/root/.nvm/versions/node/v14.17.3/bin/node',1 verbose cli   '/root/.nvm/versions/node/v14.17.3/bin/npm',1 verbose cli   'install',1 verbose cli   'mdns'
1 verbose cli ]
2 info using npm@6.14.13
3 info using node@v14.17.3
4 verbose npm-session 3c9a479254a3c45b
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 304 https://registry.npmjs.org/mdns 2817ms (from cache)
8 silly pacote tag manifest for mdns@latest fetched in 3161ms
9 timing stage:loadCurrentTree Completed in 4805ms
10 silly install loadIdealTree
11 silly install cloneCurrentTreetoIdealTree
12 timing stage:loadIdealTree:cloneCurrentTree Completed in 9ms
13 silly install loadShrinkwrap
14 timing stage:loadIdealTree:loadShrinkwrap Completed in 38ms
15 silly install loadAllDepsIntoIdealTree
16 silly resolveWithNewModule mdns@2.7.2 checking installable status
17 http fetch GET 304 https://registry.npmjs.org/bindings 1100ms (from cache)
18 silly pacote range manifest for bindings@~1.2.1 fetched in 1252ms
19 silly resolveWithNewModule bindings@1.2.1 checking installable status
20 http fetch GET 304 https://registry.npmjs.org/nan 1313ms (from cache)
21 silly pacote range manifest for nan@^2.14.0 fetched in 1419ms
22 silly resolveWithNewModule nan@2.14.2 checking installable status
23 timing stage:loadIdealTree:loadAllDepsIntoIdealTree Completed in 1720ms
24 timing stage:loadIdealTree Completed in 1867ms
25 silly currentTree temp@1.0.0
26 silly idealTree temp@1.0.0
26 silly idealTree ├── bindings@1.2.1
26 silly idealTree ├── mdns@2.7.2
26 silly idealTree └── nan@2.14.2
27 silly install generateActionsToTake
28 timing stage:generateActionsToTake Completed in 185ms
29 silly diffTrees action count 3
30 silly diffTrees add bindings@1.2.1
31 silly diffTrees add nan@2.14.2
32 silly diffTrees add mdns@2.7.2
33 silly decomposeActions action count 24
34 silly decomposeActions fetch bindings@1.2.1
35 silly decomposeActions extract bindings@1.2.1
36 silly decomposeActions preinstall bindings@1.2.1
37 silly decomposeActions build bindings@1.2.1
38 silly decomposeActions install bindings@1.2.1
39 silly decomposeActions postinstall bindings@1.2.1
40 silly decomposeActions finalize bindings@1.2.1
41 silly decomposeActions refresh-package-json bindings@1.2.1
42 silly decomposeActions fetch nan@2.14.2
43 silly decomposeActions extract nan@2.14.2
44 silly decomposeActions preinstall nan@2.14.2
45 silly decomposeActions build nan@2.14.2
46 silly decomposeActions install nan@2.14.2
47 silly decomposeActions postinstall nan@2.14.2
48 silly decomposeActions finalize nan@2.14.2
49 silly decomposeActions refresh-package-json nan@2.14.2
50 silly decomposeActions fetch mdns@2.7.2
51 silly decomposeActions extract mdns@2.7.2
52 silly decomposeActions preinstall mdns@2.7.2
53 silly decomposeActions build mdns@2.7.2
54 silly decomposeActions install mdns@2.7.2
55 silly decomposeActions postinstall mdns@2.7.2
56 silly decomposeActions finalize mdns@2.7.2
57 silly decomposeActions refresh-package-json mdns@2.7.2
58 silly install executeActions
59 silly doSerial global-install 24
60 verbose correctMkdir /root/.npm/_locks correctMkdir not in flight; initializing
61 verbose lock using /root/.npm/_locks/staging-6e75802c4ec6499a.lock for /root/temp/node_modules/.staging
62 silly doParallel extract 3
63 silly extract bindings@1.2.1
64 silly extract nan@2.14.2
65 silly extract mdns@2.7.2
66 silly tarball trying bindings@~1.2.1 by hash: sha1-FK1hE4EtLTfXLme0ystLtyZQXxE=
67 silly tarball trying nan@^2.14.0 by hash: sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
68 silly tarball trying mdns@latest by hash: sha512-NBOQT22DKvuNWVY7nKNbs6w9eGRyPwnc4ZjKOsCG2G/4wNt1+IyiHvc+5yhcAUZLG46cOY321YW7Ufz3lMtrhw==
69 timing audit submit Completed in 1081ms
70 http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/audits/quick 1079ms
71 timing audit body Completed in 45ms
72 silly extract bindings@~1.2.1 extracted to /root/temp/node_modules/.staging/bindings-08560506 (1928ms)
73 silly extract nan@^2.14.0 extracted to /root/temp/node_modules/.staging/nan-aee4678a (3822ms)
74 silly extract mdns@latest extracted to /root/temp/node_modules/.staging/mdns-ae1ea7fc (3879ms)
75 timing action:extract Completed in 3993ms
76 silly doReverseSerial unbuild 24
77 silly doSerial remove 24
78 silly doSerial move 24
79 silly doSerial finalize 24
80 silly finalize /root/temp/node_modules/bindings
81 silly finalize /root/temp/node_modules/nan
82 silly finalize /root/temp/node_modules/mdns
83 timing action:finalize Completed in 269ms
84 silly doParallel refresh-package-json 3
85 silly refresh-package-json /root/temp/node_modules/bindings
86 silly refresh-package-json /root/temp/node_modules/nan
87 silly refresh-package-json /root/temp/node_modules/mdns
88 timing action:refresh-package-json Completed in 686ms
89 silly doParallel preinstall 3
90 silly preinstall bindings@1.2.1
91 info lifecycle bindings@1.2.1~preinstall: bindings@1.2.1
92 silly preinstall nan@2.14.2
93 info lifecycle nan@2.14.2~preinstall: nan@2.14.2
94 silly preinstall mdns@2.7.2
95 info lifecycle mdns@2.7.2~preinstall: mdns@2.7.2
96 timing action:preinstall Completed in 68ms
97 silly doSerial build 24
98 silly build bindings@1.2.1
99 info linkStuff bindings@1.2.1
100 silly linkStuff bindings@1.2.1 has /root/temp/node_modules as its parent node_modules
101 silly build nan@2.14.2
102 info linkStuff nan@2.14.2
103 silly linkStuff nan@2.14.2 has /root/temp/node_modules as its parent node_modules
104 silly build mdns@2.7.2
105 info linkStuff mdns@2.7.2
106 silly linkStuff mdns@2.7.2 has /root/temp/node_modules as its parent node_modules
107 timing action:build Completed in 54ms
108 silly doSerial global-link 24
109 silly doParallel update-linked 0
110 silly doSerial install 24
111 silly install bindings@1.2.1
112 info lifecycle bindings@1.2.1~install: bindings@1.2.1
113 silly install nan@2.14.2
114 info lifecycle nan@2.14.2~install: nan@2.14.2
115 silly install mdns@2.7.2
116 info lifecycle mdns@2.7.2~install: mdns@2.7.2
117 verbose lifecycle mdns@2.7.2~install: unsafe-perm in lifecycle false
118 verbose lifecycle mdns@2.7.2~install: PATH: /root/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/root/temp/node_modules/mdns/node_modules/.bin:/root/temp/node_modules/.bin:/root/.nvm/versions/node/v14.17.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
119 verbose lifecycle mdns@2.7.2~install: CWD: /root/temp/node_modules/mdns
120 silly lifecycle mdns@2.7.2~install: Args: [ '-c','node-gyp rebuild' ]
121 silly lifecycle mdns@2.7.2~install: Returned: code: 1  signal: null
122 info lifecycle mdns@2.7.2~install: Failed to exec install script
123 timing action:install Completed in 18096ms
124 verbose unlock done using /root/.npm/_locks/staging-6e75802c4ec6499a.lock for /root/temp/node_modules/.staging
125 timing stage:rollbackFailedOptional Completed in 1503ms
126 timing stage:runTopLevelLifecycles Completed in 32740ms
127 silly saveTree temp@1.0.0
127 silly saveTree └─┬ mdns@2.7.2
127 silly saveTree   ├── bindings@1.2.1
127 silly saveTree   └── nan@2.14.2
128 warn temp@1.0.0 No description
129 warn temp@1.0.0 No repository field.
130 verbose stack Error: mdns@2.7.2 install: `node-gyp rebuild`
130 verbose stack Exit status 1
130 verbose stack     at EventEmitter.<anonymous> (/root/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
130 verbose stack     at EventEmitter.emit (events.js:375:28)
130 verbose stack     at ChildProcess.<anonymous> (/root/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
130 verbose stack     at ChildProcess.emit (events.js:375:28)
130 verbose stack     at maybeClose (internal/child_process.js:1055:16)
130 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)
131 verbose pkgid mdns@2.7.2
132 verbose cwd /root/temp
133 verbose Linux 4.19.94-ti-r42
134 verbose argv "/root/.nvm/versions/node/v14.17.3/bin/node" "/root/.nvm/versions/node/v14.17.3/bin/npm" "install" "mdns"
135 verbose node v14.17.3
136 verbose npm  v6.14.13
137 error code ELIFECYCLE
138 error errno 1
139 error mdns@2.7.2 install: `node-gyp rebuild`
139 error Exit status 1
140 error Failed at the mdns@2.7.2 install script.
140 error This is probably not a problem with npm. There is likely additional logging output above.
141 verbose exit [ 1,true ]
root@bgw00000000:~/temp# 

不知道为什么会失败,但我确实注意到一些让我放心我正在运行正确的东西的东西,例如对“/root/.nvm/versions/node/v14.17.3/bin/node”的引用,等等等等 那就是 NVM - 新安装的 - Node、NPM 等版本

我已经用谷歌搜索并尝试了所有我能做的。非常感谢您的想法、想法等!

干杯


更新


我从我的系统中完全卸载了 node、npm 和 nvm。我以非 root 用户身份登录。我重新安装了 nvm、node 和 npm。我创建了一个名为 temp 的新目录,然后 ....

debian@bgw00000000:~$ cd temp
debian@bgw00000000:~/temp$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items,and tries to guess sensible defaults.

See `npm help init` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (temp) 
version: (1.0.0) 
description: 
entry point: (index.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /home/debian/temp/package.json:

{
  "name": "temp","description": "","main": "index.js","scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },"author": "","license": "ISC"
}


Is this OK? (yes) 
debian@bgw00000000:~/temp$ ls -l
total 4
-rw-r--r-- 1 debian debian 200 Jul 17 02:35 package.json
debian@bgw00000000:~/temp$ cat package.json 
{
  "name": "temp","license": "ISC"
}
debian@bgw00000000:~/temp$ npm install mdns --save

> mdns@2.7.2 install /home/debian/temp/node_modules/mdns
> node-gyp rebuild

make: Entering directory '/home/debian/temp/node_modules/mdns/build'
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o
In file included from ../src/dns_sd.cpp:1:
../src/mdns.hpp:32:10: Fatal error: dns_sd.h: No such file or directory
 #include <dns_sd.h>
          ^~~~~~~~~~
compilation terminated.
make: *** [dns_sd_bindings.target.mk:177: Release/obj.target/dns_sd_bindings/src/dns_sd.o] Error 1
make: Leaving directory '/home/debian/temp/node_modules/mdns/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` Failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/debian/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:375:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Linux 4.19.94-ti-r42
gyp ERR! command "/home/debian/.nvm/versions/node/v14.17.3/bin/node" "/home/debian/.nvm/versions/node/v14.17.3/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/debian/temp/node_modules/mdns
gyp ERR! node -v v14.17.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 
npm WARN temp@1.0.0 No description
npm WARN temp@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mdns@2.7.2 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mdns@2.7.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/debian/.npm/_logs/2021-07-17T02_36_32_724Z-debug.log

这就是我能说明问题的最简单的方法。我将尝试不同版本的 mdns,以防万一这是一个问题,但我怀疑它更多地与 node-gyp/make/et al 有关。


更新


再次删除 NVM、Node、NPM 使用 apt-get 安装 Python 3.8.2 设置别名以便 python 执行 python3(.bashrc 文件) 重新安装 NVM、Node 和 NPM nvm install --lts(节点:14.x.x 和 NPM) nvm use --lts 全球升级到最新的 NPM:npm install npm -g 创建一个新项目: mkdir temp;cd temp;npm init; 安装有问题的节点模块,即 npm install mdns --save

我可能还做了其他我不记得的事情,但现在它似乎起作用了。我怀疑在安装 python3升级 npm 之间成功了,但同样,我现在不确定。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。