webpack5 module with extend and merge - node.js

I am working on webpack5 with node.js . Actually i am using webpack5 with latest node.js (version 18). Hw i can merege , extend another module with the webpack module. I am stuck on it and Please help me soon as possible.
I am tried with webpack-merge and not worked as expect.Also for extending a module tried with extends, but couldn`t resolved

Related

Can't resolve module 'ipfs-http-client' in react-app

I have ran into trouble with ipfs-http-client in my React app.
I'm using node 16.14.0
The error message is:
When I Ctrl + Click on 'ipfs-http-client', it still drive me to the modules file.
Solutions that I've tried, but not work:
Restart app
Reinstall module
I've tried use 33.x version, it works fine but I want to use the latest version of ipfs-http-client (57.0.3)
Please help me. Thanks a lot!
The simple Solution
When you use ipfs-http-client in the frontend you will soon also have problems using jest. The easiest way is to simply not use ipfs-http-client at all and instead use a gateway like infura and fetch() the data directly. You can use my code for that:
https://gist.github.com/aignermax/c495c98003da974d17b9c4c481ac23be
The more tricky one
The problem seems to be related to webpack 5 that does not support any Node.js functions "polyfills" anymore. The idea is to keep the frontend separate from the backend and all ipfs-http-client functions are meant to be used in backend only.
You can however still add the polyfills manually following this tutorial: Remember that "Jest" will still not work after that, so if you do unit testing you should consider using ipfs on your server instead or use "The simple Solution" above.
https://github.com/facebook/create-react-app/issues/11756#issuecomment-1001162736
I then got some webpack PolyErrors which I solved using this NPM Package:
https://www.npmjs.com/package/node-polyfill-webpack-plugin
I also Got Errors about failed to load Source-Map from source-map-loader, which will occur using WebPack5 which is included in the new React-Scripts. You fix that by using this:
Failed to parse source map
and NOW IT WORKS.

How to use the 'v8' module in react native?

I am having trouble using the v8 module in my react native app (running on node version v16.14.0). I would like to use the structuredClone() function introduced in node v17. To do this I tried to access the v8 module and use the Serialization API like so (the link suggests this module should be available in node v16).
const v8 = require('v8');
// Remove in newer versions of Node that natively support structuredClone
const structuredClone = (o) => v8.deserialize(v8.serialize(o));
When I try to run this on my android phone using expo I get "Unable to resolve module v8 from C:\Users... v8 could not be found within the project or in these directories:
node_modules"
Which I think sounds like it is trying to search my project rather than the v8 module installed with node. Any ideas why this is?
EDIT: Seems this answers my question. Alternatively, it might be possible to make it usable by using this react-native-v8 package. Can't confirm as I haven't used it.

How can I use the node.js v8 module in a react app?

I'm trying to use the serialization API from the node.js v8 module in my react app (created with create-react-app) but it doesn't seem to work.
According to the documentation it should just be a case of importing/requiring the module. When I try this, it all appears to be working as expected - no errors. I can even access methods like .serialize() and .deserialize() on the v8 object too - great. But when I try to actually run my project (using react-scripts start) I get a compilation error:
Module not found: Can't resolve 'v8' in '...'
Is it looking for a file called "v8.js" to import rather than using the node module for some reason? How do I get around this?
node_modules is only a concept when working within the node ecosystem. So it is only possible to import "v8" when within a node process.
Since you ask about a "react app" that seems to imply that you are writing something for the browser. Which now has modules which use import/export (similar to require/module.exports from node), however, that still doesn't mean that the "v8" package will be present.
Many of node's packages are C++ backed (or to use the technical term, they are "native packages") instead of being purely written in JS. Also, it should be noted that unlike dependencies listed in your "package.json" file, none of the node packages are actually downloaded when you run npm install since they are all bundled with your installation of node.

Typescript generated code fails to run due to amdefine

I'm writing a NodeJS app, using v10.8.0 and Typescript 3.2.1
TS generates JS code fine, but the code cannot be executed because of the following error:
amdefine with no module ID cannot be called more than once per file
I can see the error comes from the amdefine package, but it is actually triggered by other packages which seem to use AMD modules.
I know that adding something like this to the problematic code solves the issue:
if (typeof define !== 'function') {
var define = require('amdefine')(module)
}
but I obviously cannot edit 3rd party code..
Is there a better way to make Node work with AMD modules?
TS target is ES2016 and it uses commonjs modules. This worked fine before. But now that I have these AMD based dependencies, everything is broken.
Any help would be appreciated!
Thanks in advance.
Solved.
Amdefine has a intercept feature which adds the above code to all AMD modules automatically. This is experimental, but it seems to work.
require('amdefine/intercept');
More info on this here

node js - How do I create build for commercial usage?

I am working on node js application and it is now ready to use. I want to make exe of this application so that it can be used for commercial usage.
Up to now I have used enclose module using which I have compiled the code of application but I have found some issues in that (app got crash on idle condition). App is running good without enclose or compiled code.
I have searched on google and found some alternate modules like JXcore, Node webkit and Electron etc. but JX core giving error same as in SO question.
In node web-kit, it's functionality is not looking suitable as we need its executable and some dll's along with our code, which makes our package bulky.
I have also tried jxcore. The main problem with the exe's and with modules that we use is their ability to work with native modules, in my case the Kinect.node module. This module cannot be compiled. We need a workaround to package only this along with our .exe file. Enclose provides this workaround in its inbuilt functionality.
Also looking a response from EncloseJS, which is actually run by just one person who gives further instructions upon purchase. A purchase is needed for commercial usage.
In case of Electron, It is supporting only Electron-based application source code. So If I choose this then I have to modify my application code.
So can any one suggest me what can I do to make exe file from node js code there?
Thank you!
I had the same issue before, the node js application close when running in background. now i am using process manager2 (pm2), it is working fine and if the application is crash due to any other reason it is automatically started again.
I have gotten my answer:
First, reason was DiskDB database, it was not compatible with the node webkit so that is why I was getting error of native modules.
Now I am using sqlite3 module for local database. It is better than DiskDB.
Second, One reason was free version of enclose, Paid version of Enclose JS module ignores the timeout issue which I was getting.
This way I have resolved my question.

Resources