# TypeError: Invalid host defined options

**URL:** <https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118>\
**Category:** General\
**Tags:** http-request\
**Created:** [17 October 2023 14:22 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118 "2023-10-17T14:22:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![KeoJam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/keojam/32/83858_2.png) [@KeoJam](https://discourse.nodered.org/u/KeoJam)\
**Post date:** [17 October 2023 14:22 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/1 "2023-10-17T14:22:47Z")

</div>

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:

```auto
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:

```auto
{
  "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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [17 October 2023 14:54 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/2 "2023-10-17T14:54:25Z")

</div>

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

````auto
```
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?

```auto
"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)](https://discourse.nodered.org/t/node-red-standalone-executable/77963/12)

---

<div class="post-metadata">

**Author:** ![KeoJam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/keojam/32/83858_2.png) [@KeoJam](https://discourse.nodered.org/u/KeoJam)\
**Post date:** [17 October 2023 14:56 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/3 "2023-10-17T14:56:02Z")

</div>

this is the error in cmd:

```auto
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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [17 October 2023 15:02 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/4 "2023-10-17T15:02:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KeoJam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/keojam/32/83858_2.png) [@KeoJam](https://discourse.nodered.org/u/KeoJam)\
**Post date:** [17 October 2023 15:12 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/5 "2023-10-17T15:12:55Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![KeoJam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/keojam/32/83858_2.png) [@KeoJam](https://discourse.nodered.org/u/KeoJam)\
**Post date:** [17 October 2023 15:14 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/6 "2023-10-17T15:14:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [17 October 2023 16:09 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/7 "2023-10-17T16:09:30Z")

</div>

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.

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

```

**EDIT**  
Don't use glob patterns for `scripts` - increases the size massively 😅

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [17 October 2023 16:19 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/8 "2023-10-17T16:19:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KeoJam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/keojam/32/83858_2.png) [@KeoJam](https://discourse.nodered.org/u/KeoJam)\
**Post date:** [17 October 2023 16:42 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/9 "2023-10-17T16:42:21Z")

</div>

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

```auto
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！

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [17 October 2023 17:19 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/10 "2023-10-17T17:19:58Z")

</div>

Seems its a problem with `pkg`

- [Dynamic import - import() - fails when the code is packaged into an executable · Issue #1603 · vercel/pkg · GitHub](https://github.com/vercel/pkg/issues/1603)

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

- [https://github.com/node-red/node-red/blob/ee48a2f2bf32768ecd1b389c0b32389b9ec74d36/packages/node\_modules/%40node-red/nodes/core/network/21-httprequest.js#L19](https://github.com/node-red/node-red/blob/ee48a2f2bf32768ecd1b389c0b32389b9ec74d36/packages/node_modules/%40node-red/nodes/core/network/21-httprequest.js#L19)

Seems this is for the developers of `pkg` to fix.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 December 2023 17:20 UTC](https://discourse.nodered.org/t/typeerror-invalid-host-defined-options/82118/11 "2023-12-16T17:20:51Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
