cfsghost / npk

Node.js packaging utility
137 stars 18 forks source link

用 "爸爸認不得" --dad-doesnt-recognize 出現錯誤 #1

Closed hank7444 closed 10 years ago

hank7444 commented 10 years ago

events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:980:11) at Process.ChildProcess._handle.onexit (child_process.js:771:34)

cfsghost commented 10 years ago

是打包完成後,執行應用程式時出現錯誤,還是打包的過程中出現錯誤?

Fred

hank7444 commented 10 years ago

Fred大:

是打包過程發生錯誤, 我拿您的eample測試, 環境是mac, 指令如下:
npk purejs/ --dad-doesnt-recognize

Hank

cfsghost commented 10 years ago

『爸爸不認得』需要用到node-gyp和Compiler,一個能編譯Native Module的環境。

可以嘗試先用NPM安裝node-gyp看看。

hank7444 commented 10 years ago

好的~我先試試看~謝謝您

hank7444 commented 10 years ago

不知道還缺了啥QQ

gyp info it worked if it ends with ok gyp info using node-gyp@0.12.1 gyp info using node@0.10.21 | darwin | x64

gyp info spawn python

gyp info spawn args [ '/usr/local/lib/node_modules/node-gyp/gyp/gyp_main.py',

gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make',

gyp info spawn args '-I', gyp info spawn args '/Users/hank7444/Documents/NodeProject/purejs/out/app.js/build/config.gypi', gyp info spawn args '-I',

gyp info spawn args '/usr/local/lib/node_modules/node-gyp/addon.gypi',

gyp info spawn args '-I', gyp info spawn args '/Users/hank7444/.node-gyp/0.10.21/common.gypi', gyp info spawn args '-Dlibrary=shared_library',

gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/Users/hank7444/.node-gyp/0.10.21',

gyp info spawn args '-Dmodule_root_dir=/Users/hank7444/Documents/NodeProject/purejs/out/app.js',

gyp info

spawn args '--depth=.', gyp info spawn args '--generator-output', gyp info

spawn args 'build', gyp info

spawn args '-Goutput_dir=.' ]

gyp info spawn make

gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]

CXX(target) Release/obj.target/npk/output.o

In file included from ../output.cpp:1: In file included from /Users/hank7444/.node-gyp/0.10.21/deps/v8/include/v8.h:41: /Users/hank7444/.node-gyp/0.10.21/deps/v8/include/v8stdint.h:34:10 : fatal error: 'stdio.h' file not found

include

     ^

1 error generated.

make: *\ [Release/obj.target/npk/output.o] Error 1

gyp ERR! build error

gyp ERR! stack Error: make failed with exit code: 2

gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/node-gyp/lib/build.js:267:23) gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:98:17) gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:789:12)

gyp ERR! System Darwin 13.0.0

gyp ERR! command "node" "/usr/local/bin/node-gyp" "configure" "build" gyp ERR! cwd /Users/hank7444/Documents/NodeProject/purejs/out/app.js gyp ERR! node -v v0.10.21 gyp ERR! node-gyp -v v0.12.1 gyp ERR! not ok

cfsghost commented 10 years ago

似乎是缺少一些gcc的東西,你可以參考這篇文章先將Mac上的編譯器工具安裝好:

http://cnodejs.org/topic/51061b00df9e9fcc588fb2d0

hank7444 commented 10 years ago

ok~

hank7444 commented 10 years ago

剛剛測試成功了! 謝謝Fred大,

不過有的小疑問, 如果我要把整個專案包起來使用, 請問node_modules/ 下的套件也需要在package.json裡面一一指定嗎?

我剛剛把node express的專案的app.js與相應的js檔案包起來, 但是無法成功執行..

cfsghost commented 10 years ago

node_modules底下的Module,就算一一去指定,也仍然沒有辦法被正常使用,這部分還尚未實作。

但你可以試試改寫程式,把:

require('express');

改寫成

require('./node_modules/express');

然後打包看看。

hank7444 commented 10 years ago

node_modules部分已經ok了, 測試過後可以正常使用module的功能, 現在OSX跟Linux都有成功, 剩windows環境還不行, 不過應該是gcc環境的關係:P

不過還是很謝謝您, 這模組很實用, 解決了我們想要把nodejs核心部分封裝的需求:)

cfsghost commented 10 years ago

:-)

shenqihui commented 10 years ago

@hank7444 请问express是需要把express模块里面的东西全部写成require('./node_modules/**')形式吗?

hank7444 commented 10 years ago

Hi shenqihui:

我貼一段code給你看:

underscore是nodejs套件, 放在node_modules/ b是同一層的其他js檔案

// a.js

"use strict";

var underscore = require('underscore');

var B = require('./b');

var name = 'Test variable';

module.exports = {
    test: function() {
        console.log('hello world');
        underscore.each([1,2,3,4,5,6], function(value) {
            console.log(value);
        });
    },
    test2: function() {
        console.log('name: ' + name);
    }
}

console.log('Entry point!');
hank7444 commented 10 years ago

然後這是clien端使用封裝後套件的code

// test.js

global.require = require;
global.module = module;

var aa = require('./npk.node');

aa.test2(); 
shenqihui commented 10 years ago

那能不能把underscore也封装了?

hank7444 commented 10 years ago

應該是一起封裝了, 要不我把代碼打包寄給你?

shenqihui commented 10 years ago

如果不算泄露代码的话,欢迎打包发来给我,谢谢 shenqihui0920 at gmail.com 强烈感谢。