我試圖在Ubuntu 14.04運行一個簡單的腳本的NodeJS的大門,其內容如下:無效的ELF頭了運行簡單的腳本的NodeJS
http = require('http');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type': 'text/plain' });
res.end('Hello World \n');
}).listen(80, '127.0.0.1');
我已經通過了安裝的NodeJS說明found here。下面是我從該鏈接遵循的摘錄:
Option 2: Install Node.js with Ubuntu Package Manager
To install Node.js, type the following command in your terminal:
sudo apt-get install nodejs
Then install the Node package manager, npm:
sudo apt-get install npm
Create a symbolic link for node, as many Node.js tools use this name to execute.
sudo ln -s /usr/bin/nodejs /usr/bin/node
我這樣做,證明這兩個軟件包安裝:
但我不能用我的.node檔案,而不要抱怨與此錯誤:
[email protected]:/var/www/html/nodetest$ node test.node
module.js:356
Module._extensions[extension](this, filename);
^
Error: /var/www/html/nodetest/test.node: invalid ELF header
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:945:3
我已經卸載和重新安裝節點以及NPM,但它仍然無法正常工作...我運行Ubuntu 14.04 LTS 64位。
更多信息:
我決定從源代碼和https://github.com/nodejs/node.git克隆master
,建設它,然後運行相同的腳本之後打造,這是我得到的錯誤:
[email protected]:/var/www/html/nodetest$ ~/node/node test.node
module.js:600
return process.dlopen(module, path._makeLong(filename));
^
Error: /var/www/html/nodetest/test.node: invalid ELF header
at Object.Module._extensions..node (module.js:600:18)
at Module.load (module.js:490:32)
at tryModuleLoad (module.js:449:12)
at Function.Module._load (module.js:441:3)
at Module.runMain (module.js:607:10)
at run (bootstrap_node.js:414:7)
at startup (bootstrap_node.js:139:9)
at bootstrap_node.js:529:3
這是相同的錯誤,顯然,與不同的堆棧跟蹤。
什麼給?
控制檯輸出引述看起來比圖片要好得多,因爲僅僅反差太大介紹(和你沒有虛擬機下運行它W/O副本 - 我可以看到可用的膏狀物)。 – agg3l
只是一個瘋狂的猜測 - 不能是關於你的腳本錯誤的文件編碼node.js無法解釋?像UTF8 + BOM或UTF16 ... – agg3l
我只是在我的Pi上運行相同的步驟運行Raspbian Jessie,同樣的事情發生。我還沒有檢查文件的編碼,但是nodejs需要什麼編碼? – Brandon