TypeError: Invalid host defined options

I use express to start Node-red, it's run well use cmd by command "node index.js". But when i use "npm pkg" to pack into the app,and run the app it show [warn] [node-red/httprequest] TypeError: Invalid host defined options, and use wmi node [error] [wmi:Windows or macOS?] Failed to load module : TypeError: Invalid host defined options. What can i do for it?
this is my index.js:

var http = require('http');
var express = require("express");
var RED = require("node-red");

// Create an Express app
var app = express();

// Add a simple route for static content served from 'public'
app.use("/",express.static("public"));

// Create a server
var server = http.createServer(app);

// Create the settings object - see default settings.js file for other options

var nrSettings = require("./settings.js"); // Node-Red settings file

// Initialise the runtime with a server and settings
RED.init(server,nrSettings);

// Serve the editor UI from /httpAdminRoot
app.use(nrSettings.httpAdminRoot, RED.httpAdmin);

// Serve the http nodes from /
app.use(nrSettings.httpNodeRoot, RED.httpNode);

server.listen(8000);

// Start the runtime
RED.start();

And this is my package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2",
    "node-red": "^3.1.0"
  },
  "bin":"index.js",
  "pkg": {
	"scripts": ["node_modules/@node-red/nodes/core/network/21-httprequest.js"],
    "assets": [
		"node_modules/@node-red",
		"node_modules/@node-red/nodes/core/network/21-httprequest.html"
	]
  }
}

pgk is look well too:

E:\project\>pkg -t win -C GZip package.json
> pkg@5.8.1
compression:  GZip
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\SmartFactoryNode\node_modules\form-data-encoder\lib\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\SmartFactoryNode\node_modules\lowercase-keys\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\SmartFactoryNode\node_modules\p-cancelable\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\SmartFactoryNode\node_modules\responselike\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\SmartFactoryNode\node_modules\mimic-response\index.js
> Warning Failed to make bytecode node18-x64 for file C:\snapshot\SmartFactoryNode\node_modules\normalize-url\index.js

Can any one help me?

Its hard to decipher the error and your request, please just provide the error as it appears

```
CMD Output
```

Also, are you doing more then just starting Node RED?
if not - you can start Node RED directly and still use pkg

Not sure why you need this?

"scripts": ["node_modules/@node-red/nodes/core/network/21-httprequest.js"],

See here for packaging up Node RED : Node-RED Standalone Executable - General - Node-RED Forum (nodered.org)

this is the error in cmd:

17 Oct 22:14:16 - [info] Node-RED version: v3.1.0
17 Oct 22:14:16 - [info] Node.js  version: v18.5.0
17 Oct 22:14:16 - [info] Windows_NT 10.0.19044 x64 LE
17 Oct 22:14:17 - [info] Loading palette nodes
17 Oct 22:14:18 - [info] Dashboard version 3.6.0 started at /ui
17 Oct 22:14:18 - [warn] ------------------------------------------------------
17 Oct 22:14:18 - [warn] [node-red/httprequest] TypeError: Invalid host defined options
17 Oct 22:14:18 - [warn] ------------------------------------------------------
17 Oct 22:14:18 - [info] Context store  : 'default' [module=memory]
17 Oct 22:14:18 - [info] User directory : E:/project/data/.nodered/
17 Oct 22:14:18 - [warn] Projects disabled : editorTheme.projects.enabled=false
17 Oct 22:14:18 - [info] Flows file     : E:\project\data\.nodered\myflows.json
17 Oct 22:14:19 - [info] Starting flows
17 Oct 22:14:19 - [error] [wmi:Windows or macOS?] Failed to load module : TypeError: Invalid host defined options
17 Oct 22:14:19 - [error] [wmi:Windows or macOS?] Function node failed to load external modules
17 Oct 22:14:19 - [error] [wmi:Windows or macOS?] Failed to load module : TypeError: Invalid host defined options
17 Oct 22:14:19 - [error] [wmi:Windows or macOS?] Function node failed to load external modules
17 Oct 22:14:19 - [info] Started flows

@marcus-j-davies

Is there a reason you are starting Node RED yourself, and including a random script portion?

May I suggest trying the solution I linked to, if you don't do anything special other then starting Node RED?

You can "Hard Installed" nodes if you need to

because if i remove the "scripts": ["node_modules/@node-red/nodes/core/network/21-httprequest.js"] and pkg and run,it show error:

17 Oct 23:08:07 - [info] Node-RED version: v3.1.0
17 Oct 23:08:07 - [info] Node.js  version: v18.5.0
17 Oct 23:08:07 - [info] Windows_NT 10.0.19044 x64 LE
17 Oct 23:08:08 - [info] Loading palette nodes
17 Oct 23:08:10 - [info] Dashboard version 3.6.0 started at /ui
17 Oct 23:08:10 - [warn] ------------------------------------------------------
17 Oct 23:08:10 - [warn] [node-red/httprequest] Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'got' imported from C:\snapshot\SmartFactoryNode\node_modules\@node-red\nodes\core\network\21-httprequest.js
Did you mean to import got/dist/source/index.js?
17 Oct 23:08:10 - [warn] ------------------------------------------------------
17 Oct 23:08:10 - [info] Context store  : 'default' [module=memory]
17 Oct 23:08:10 - [info] User directory : E:/project/SmartFactoryNode/data/.nodered/
17 Oct 23:08:10 - [warn] Projects disabled : editorTheme.projects.enabled=false
17 Oct 23:08:10 - [info] Flows file     : E:\project\SmartFactoryNode\data\.nodered\myflows.json
17 Oct 23:08:10 - [info] Starting flows
17 Oct 23:08:10 - [error] [wmi:Windows or macOS?] Failed to load module : TypeError: Invalid host defined options
17 Oct 23:08:10 - [error] [wmi:Windows or macOS?] Function node failed to load external modules
17 Oct 23:08:10 - [error] [wmi:Windows or macOS?] Failed to load module : TypeError: Invalid host defined options
17 Oct 23:08:10 - [error] [wmi:Windows or macOS?] Function node failed to load external modules

thanks i'll try your solution, because i have anthor node project. I want to start in a app.

Mmm..

Seems recent versions of Node RED do indeed require the need for
"scripts": ["node_modules/@node-red/nodes/core/network/21-httprequest.js"],

But maybe try.

 "scripts": [
      "./node_modules/**/*.js"
    ]

EDIT
Don't use glob patterns for scripts - increases the size massively :sweat_smile:

Seems it still produces

[node-red/httprequest] TypeError: Invalid host defined options

Not sure where to look currently - I think the got library is playing games with pkg - if I get more time, I will research, others may chip if otherwise

yes ,I have try your script which you link to, but also saw belong:

18 Oct 00:35:04 - [warn] [node-red/httprequest] Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'got' imported from C:\snapshot\SmartFactoryNode\node_modules\@node-red\nodes\core\network\21-httprequest.js
Did you mean to import got/dist/source/index.js?

thanks for you research,hope it can be solved!

Seems its a problem with pkg

And Node RED uses import for got as its an ES Module

Seems this is for the developers of pkg to fix.