Rickardo
Rickardo

Reputation: 39

How to fix "cannot find module'./node'' while compiling with pkg

the nodejs script works when I do node main.js but when I compile it into an executable with pkg it gives me this error :

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

Error: Cannot find module './node' Require stack:

  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 (node:internal/modules/cjs/loader:933:15) at Function._resolveFilename (pkg/prelude/bootstrap.js:1955:46) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at Module.require (pkg/prelude/bootstrap.js:1855:31) at require (node:internal/modules/cjs/helpers:102:18) at Object. (C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js:3:19) at Module._compile (pkg/prelude/bootstrap.js:1930:22) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) { code: 'MODULE_NOT_FOUND', requireStack: [ 'C:\snapshot\project\node_modules\hookcord\node_modules\snekfetch\src\index.js', 'C:\snapshot\project\node_modules\hookcord\src\fire.js', 'C:\snapshot\project\node_modules\hookcord\src\index.js', 'C:\snapshot\project\node_modules\hookcord\index.js', 'C:\snapshot\project\main.js' ], pkg: true }

Upvotes: 3

Views: 1719

Answers (1)

BugaBuga
BugaBuga

Reputation: 509

Add not found module to package.json like this

"pkg": {
    "assets": [
      "./node"
    ]
}

Upvotes: 0

Related Questions