npm - Object function Object() { [native code] } has no method 'assign' - node.js

First of all, I did see the similar documents:
Node.js TypeError: Object function Object() { [native code] } has no method 'assign'
TypeError: Object function Object() { [native code] } has no method 'method'
However..
I am using node version 0.10.48 (my app uses deprecated node api so I rather stay on this version).
whenever I try to install a new module, or even run scripts that require modules, I receive the following error:
typeerror object function object() native code has no method 'assign'
I cannot even use npm v or npm install/uninstall..
How do I get rid of this error? I simply cannot do anything on the terminal :(

You could try this: https://nodejs.org/en/download/package-manager/#osx
curl "https://nodejs.org/dist/latest/node-${VERSION:-$(wget -qO- https://nodejs.org/dist/latest/ | sed -nE 's|.*>node-(.*)\.pkg</a>.*|\1|p')}.pkg" > "$HOME/Downloads/node-latest.pkg" && sudo installer -store -pkg "$HOME/Downloads/node-latest.pkg" -target "/"
Worked for me on Amazon Linux as well (different command).
issues17886 (https://github.com/npm/npm/issues/17996)

Related

'The "path" argument must be of type string. Received null' in electron-json-storage

I'm using eletron-json-storage like this:
settings.js:
const storage = require('electron-json-storage');
const defaultStoragePath = storage.getDefaultDataPath();
// Value: C:\Users\10467\AppData\Roaming\maplateditor\storage
...
defaultStorage() {
console.log("Check defaultStorage value");
console.log(defaultStoragePath);
// C:\Users\10467\AppData\Roaming\maplateditor\storage
storage.setDataPath(defaultStoragePath);
console.log(storage.getDataPath());
// C:\Users\10467\AppData\Roaming\maplateditor\storage
return storage;
}
...
this.defaultStorage().get(...)
And I checked every times variable defaultStoragePath was sure to set.
But electron-json-storage causes error:
(anonymous) # VM75 renderer_init.js:93
VM75 renderer_init.js:93 TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
at validateString (VM19 validators.js:124)
at Object.resolve (VM28 path.js:139)
at mkdirP (VM113 F:\github\MaplatEditor\node_modules\mkdirp\index.js:25)
at VM91 F:\github\MaplatEditor\node_modules\electron-json-storage\lib\storage.js:527
at nextTask (VM93 F:\github\MaplatEditor\node_modules\async\dist\async.js:5327)
at next (VM93 F:\github\MaplatEditor\node_modules\async\dist\async.js:5334)
at VM93 F:\github\MaplatEditor\node_modules\async\dist\async.js:972
at VM91 F:\github\MaplatEditor\node_modules\electron-json-storage\lib\storage.js:524
at nextTask (VM93 F:\github\MaplatEditor\node_modules\async\dist\async.js:5327)
at Object.waterfall (VM93 F:\github\MaplatEditor\node_modules\async\dist\async.js:5337)
Is this a bug?
How can I avoid this?
Environments are:
node.js: 16.13.1
electron: 13.6.6
electron-json-storage: 4.5.0
===
Additional info:
This error not occurred with electron: 11.5.0
The difference of my code between electron: 11.5.0 and electron: 13.6.6 is:
On electron 11.5.0: Call settings.js code by:
const settings = require('electron').remote.require('./settings').init();
On electron 13.6.6: Call settings.js code through preload.js:
window.settingsBackend = require('./settings');
Maybe this difference causes different results..
Finally I found the reason...
I call "electron-json-storage" inside of "preload.js".
I don't know "preload.js" is worked on renderer process.
I must use electron-json-storage on main process.
I realized that under the contextIsolation environment, I need to completely rethink my architecture from the nodeIntegration era configuration.
====
I created example for using electron-json-storage under contextIsolation environment for people who will have similar question in future:
https://gist.github.com/kochizufan/a467c6b76390c6f1c41260614cb06a5c
This works well.
NOTE: Error handling or avoiding multiple registration of api are totally omitted in this example.
Any points for improvement are welcome.

In Electron, using "typeof" causes TypeError: Cannot assign to read only property

I got a doozie here. In Electron's main process, I require in the function below to setup event handlers with ipcMain. This keeps the main.js file a little more streamlined. All went swimmingly until I wrote some validation code to ensure that the user passes in an object. I use typeof all the time for this purpose, and never have I had an issue. But in Electron I am getting:
A JavaScript error occurred in the main process - TypeError: Cannot
assign to read only property 'exports' of object '# '
The code:
const {ipcMain} = require('electron');
function ipcSetup() {
ipcMain.on('123', function(event, arg) {
// this blows chunks...
if(arg && typeof arg === 'object') {
console.log(`All good....`);
}
// and if you comment that out, this use of "typeof" does the same thing
console.log(typeof arg);
// and to eliminate 'arg' as the issue...
let a = 1;
console.log(typeof a); // expect 'number', get Exception
});
}
module.exports = ipcSetup;
I didn't know if Electron is using Object.defineProperty to make arg read only, but typeof is not making an assignment here anyway, and I eliminated arg so this error makes no sense. Environment is Electron 1.8.4 on Node 8.2.1 using electron-vue
If you're importing that module in another module that uses ES6 import/export syntax, using typeof apparently causes this. I think this is because webpack doesn't support mixing the two syntaxes. But it is quite funny that it would work fine if you didn't use the typeof operator...

TypeError: stream is undefined

Can't add a database connection to my small react app, i tried a bunch of npm modules: sqlite, sqlite3, realm. All fall back with type error:
TypeError: stream is undefined
i do absolutely nothing, just added a require statement in my component case that error:
import db from 'sqlite';
or:
var sqlite = require('sqlite3').verbose();
The last trace string:
(function (process){
module.exports = function (blocking) {
[process.stdout, process.stderr].forEach(function (stream) {
if (stream._handle && stream.isTTY && typeof stream._handle.setBlocking === 'function') {
stream._handle.setBlocking(blocking)
}
})
}
and real fails on building, with Error: Cannot find module 'AccessibilityInfo'
Your last trace points to the content of set-blocking npm module. Usually it is used by npmlog. It requires process.stderr and process.stdout to be present. In your case they aren't. If you are running the app in Electron that might be the case.
It probably means that you are attempting to run a nodejs library in the browser, and that will not work. You might be able to browserify the library.

TypeError: has no method 'async'

I'm trying to run the Async example and have the following code:
registerSuite({
name: 'Test Dashboard empty after removing all projects and data',
setup: function () {
var dfd = this.async(1000);
console.info('\n In setup');
remote = this.remote;
remote.setWindowSize(1024,768);
When I run this, I'm seeing the following error:
TypeError: Object #<Suite> has no method 'async'
at Suite.registerSuite.setup <tests/dashboard/dashboard_empty.js:18:28>
at <Suite.target.(anonymous function).dispatcher [as setup] (/home/bkuhlman/internjs_func/Lopez-Internjs-Func/node_modules/intern/node_modules/dojo/aspect.js:95:31)>
at callOnSuite <node_modules/intern/lib/Suite.js:157:42>
at call <node_modules/intern/lib/Suite.js:208:13>
at Suite.run <node_modules/intern/lib/Suite.js:306:4>
at <node_modules/intern/lib/Suite.js:237:13>
at signalListener <node_modules/intern/node_modules/dojo/Deferred.js:37:21>
at Promise.then.promise.then <node_modules/intern/node_modules/dojo/Deferred.js:258:5>
at runTest <node_modules/intern/lib/Suite.js:236:46>
at <node_modules/intern/lib/Suite.js:249:7>
What am I missing?
Thanks,
Brad
It is as the error describes. setup is a suite lifecycle method, not a test method, so it has no this.async. If you need to perform an asynchronous operation from a lifecycle method you will need to return a promise. This will be addressed in a future version of Intern.

Node-Webkit with external module containing native code

I'm using node-webkit with an external module called edge.
According to the node-webkit docs modules that contain native code must be recompiled using nw-gyp as oppose to node-gyp. I was able to recompile without error and node-webkit seems to import the module OK.
Heres my code. The code I'm trying to use:
var edge = require('edge.node');
var hello = edge.func(function () {/*
async (input) =>
{
return ".NET welcomes " + input.ToString();
}
*/});
hello('Node.js', function (error, result) {
if (error) throw error;
console.log(result);
});
Which throws the following error when run within node-webkit.
Uncaught TypeError: Object [object Object] has no method 'func'
If write the object out to console.log I can see:
Object {initializeClrFunc: function}
initializeClrFunc: function () { [native code] }
__proto__: Object
So the module seems to have loaded. If I run the same code outside of node-webkit, everything works perfectly and I can access the func function. This is driving me crazy - and any help would be really appreciated.
func method is provided by edge.js, the wrapper around edge.node native module. So you should replace require('edge.node') by require('edge').

Resources