NodeJS MODULE_TYPELESS_PACKAGE_JSON error after nodejs update

Re: NodeJS MODULE_TYPELESS_PACKAGE_JSON error after nodejs update

by Aleksi Postari -
Number of replies: 1
Update: I think I just fixed this. After updating NodeJS to the latest version, I opened my jobe server and edited the file /var/www/html/jobe/application/libraries/nodejs_task.php. First, I tried adding just the --input-type=module to this line array parameters: $this->default_params['interpreterargs'] = array('--use_strict'); but it caused another new ugly error:

***Run error***
node:internal/modules/esm/resolve:1032
if (inputTypeFlag) { throw new ERR_INPUT_TYPE_NOT_ALLOWED(); }
^

Error [ERR_INPUT_TYPE_NOT_ALLOWED]: --input-type can only be used with string input via --eval, --print, or STDIN
at defaultResolve (node:internal/modules/esm/resolve:1032:32)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:554:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:523:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:481:36)
at TracingChannel.tracePromise (node:diagnostics_channel:337:14)
at ModuleLoader.import (node:internal/modules/esm/loader:480:21)
at node:internal/modules/cjs/loader:1373:28
at asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:11)
at Object.runEntryPointWithESMLoader (node:internal/modules/run_main:139:19) {
code: 'ERR_INPUT_TYPE_NOT_ALLOWED'

Now, I removed that --input-type=module parameter from the array and changed the executable javascript file to be saved as .mjs (module javascript) instead of .js extension by editing these two functions (compile and getTargetFile):


Original functions:

public function compile() {
$this->executableFileName = $this->sourceFileName;
if (strpos('.js', $this->executableFileName) != strlen($this->executableFileName) - 3) {
$this->executableFileName .= '.js';
}
if (!copy($this->sourceFileName, $this->executableFileName)) {
throw new exception("Node_Task: couldn't copy source file");
}
}

public function getTargetFile() {
return $this->sourceFileName;
}


And edited functions to make the runnable script be saved as .mjs:

public function compile() {
$this->executableFileName = preg_replace('/\.js$/', '.mjs', $this->sourceFileName);
if (!copy($this->sourceFileName, $this->executableFileName)) {
throw new exception("Node_Task: couldn't copy source file");
}
}

public function getTargetFile() {
return preg_replace('/\.js$/', '.mjs', $this->sourceFileName);
}


Right now, it seems like it's all working :)
In reply to Aleksi Postari

Re: NodeJS MODULE_TYPELESS_PACKAGE_JSON error after nodejs update

by Richard Lobb -
Thanks for posting, Aleksi. It looks like we'll have to make these changes - or something similar - for the next release.