2017-09-28 2 views
0

컴파일 된 node.js 앱에서 간단한 데이터베이스를 사용하고 싶습니다. 이 데이터베이스를 별도로 설치하지 않고도 가능합니까? 즉, 데이터베이스를 .exe 파일에 포함 시켜서 해당 파일을 복사하고 실행할 수 있습니다.node.js 실행 패키지에 sqlite3를 패키지하는 방법은 무엇입니까?

나는 .exe 파일을 생성 pkg을 사용하고 있는데 잘 작동하지만, 나는 다음과 같은 경고를 실행하려고 할 때 나는 sqlite3 NPM 모듈을 한 .exe 오류를 사용할 때 :

pkg/prelude/bootstrap.js:1155 
     throw error; 
    ^

Error: Cannot find module 'C:\snapshot\sqlite\node_modules\sqlite3\lib\binding\node-v51-win32-x64\node_sqlite3.node' 
1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath. 
    at Function.Module._resolveFilename (module.js:470:15) 
    at Function.Module._resolveFilename (pkg/prelude/bootstrap.js:1252:46) 
    at Function.Module._load (module.js:418:25) 
    at Module.require (module.js:498:17) 
    at Module.require (pkg/prelude/bootstrap.js:1136:31) 
    at require (internal/module.js:20:19) 
    at Object.<anonymous> (C:\snapshot\sqlite\node_modules\sqlite3\lib\sqlite3.js:4:15) 
    at Module._compile (pkg/prelude/bootstrap.js:1226:22) 
    at Object.Module._extensions..js (module.js:580:10) 
    at Module.load (module.js:488:32) 

보인다 여기에 고정 된 sqlite3 버그와 유사 : https://github.com/zeit/pkg/issues/183 (버그가 수정 된 이후 사용자 문제라고 생각 함)

오류 메시지를 보면 ...../bide_sqlit3.node 파일을 찾을 수없는 것 같습니다. 그리고 node_modules/ 내 개발 env (모듈이 작동하는 곳)에서 그 파일을 찾을 수 없습니다. 그래서 파일이 실행 파일에 포함되지 않는 것으로 가정하고 그 일을 할 필요가 :

  1. pkg이 경로로 파일의 바이너리
  2. 변경합니다 경로에서 파일을 맺습니다 이진 파일

zeit/pkg으로 어떻게해야합니까? 또는 이것이 더 정확한 경우 : npm이 바이너리를 node_modules에 설치 한 다음 해당 바이너리를 참조하도록하려면 어떻게해야합니까?

답변

0

빌드 된 노드 -sqlite3.node는 pkg로 빌드 한 이진 파일 (this issue에 설명 된대로)과 같은 디렉토리에 두어야합니다. 이 파일은 node_modules/sqlite3/lib/binding/node-vxx-xxxxx-xxx/node_sqlite3.node에서 찾을 수 있습니다.

또한 sqlite3을 빌드 한 동일한 노드 버전의 pkg로 프로젝트를 빌드해야합니다.

+0

작동하지 않습니다.이 질문이 표시됩니다. https://stackoverflow.com/questions/47789200/how-to-use-pkg-to-make-node-app-an-executable-with-a-native-dependency –

+0

@ simon-pr : 내 답변에는 설명서 (https://github.com/zeit/pkg#native-addons)가 반영되어 있으므로 문제는 pkg의 버그 일 수 있습니다. –

관련 문제