Closed raphael10-collab closed 3 years ago
This kind of problem seems solved with webpack aliases:
webpack.helpers.js
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
const path = require('path');
const cwd = process.cwd();
// Creates Webpack Aliases using CWD path
const createWebpackAliases = (als) => {
const result = {};
for (const name in als) {
result[name] = path.join(cwd, als[name]);
}
return result;
};
// Export webpack helpers
module.exports = {
createWebpackAliases,
};
webpack.aliases.js :
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { createWebpackAliases } = require('./webpack.helpers');
// Webpack aliases to resolve
const aliases = createWebpackAliases({
'@src': 'src',
'@app': 'src/app',
'@static': 'src/static',
'jsonfile': './node_modules/fs-extra/node_modules/jsonfile',
'nanoid/random': './node_modules/nanoid',
'nanoid/format': './node_modules/nanoid'
});
// Export aliases
module.exports = aliases;
But now another problem has come :
(node:26402) UnhandledPromiseRejectionWarning: Error: No native build was
found for platform=linux arch=x64 runtime=electron abi=82 uv=1 libc=glibc
node=12.16.3 electron=10.2.0 webpack=true
loaded from: /home/marco/webMatters/electronMatters/IpfsPlaying
/.webpack/main
at Function.module.exports../node_modules/node-gyp-
build/index.js.load.path (/home/marco/webMatters/electronMatters/IpfsPlaying
/.webpack/main/index.js:193915:9)
at load (/home/marco/webMatters/electronMatters/IpfsPlaying/.webpack
/main/index.js:193877:30)
at Object../node_modules/leveldown/binding.js (/home/marco/webMatters
/electronMatters/IpfsPlaying/.webpack/main/index.js:130044:101)
at __webpack_require__ (/home/marco/webMatters/electronMatters/IpfsPlaying
/.webpack/main/index.js:21:30)
at Object../node_modules/leveldown/leveldown.js (/home/marco/webMatters
/electronMatters/IpfsPlaying/.webpack/main/index.js:130158:17)
at __webpack_require__ (/home/marco/webMatters/electronMatters/IpfsPlaying
/.webpack/main/index.js:21:30)
at Object../node_modules/level/level.js (/home/marco/webMatters
/electronMatters/IpfsPlaying/.webpack/main/index.js:130032:111)
at __webpack_require__ (/home/marco/webMatters/electronMatters/IpfsPlaying
/.webpack/main/index.js:21:30)
at new LevelDatastore (/home/marco/webMatters/electronMatters/IpfsPlaying
/.webpack/main/index.js:62350:23)
at Object.createBackend [as create] (/home/marco/webMatters
/electronMatters/IpfsPlaying/.webpack/main/index.js:111452:10)
(node:26402) UnhandledPromiseRejectionWarning: Unhandled promise rejection.
This error originated either by throwing inside of an async function without a
catch block, or by rejecting a promise which was not handled with .catch().
To terminate the node process on unhandled promise rejection, use the CLI flag
`--unhandled-rejections=strict` (see https://nodejs.org
/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:26402) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.
As you can see from here: https://github.com/ipfs/js-ipfs/issues/3508#issuecomment-772772507 and from here: https://github.com/ipfs/js-ipfs/issues/3508#issuecomment-773151528 I have this situation:
This is the package.json
When using ipfs in main.ts I get this error:
People of IPFS Project made, kindly, thoughrough analysis of the problem, discovering that there is a collision between two versions of jsonfile:
There are two copies of jsonfile in my node_modules folder:
I removed all the packages not stricly required for ipfs and for a bare minimum electron-react-typescript app. And discovered that, in accordance what was already found by IPFS's people, these are the modules which depend on jsonfile :
If I remove the jsonfile v4 I get the error: "An unhandled exception has occured inside Forge":
In a nutshell the problem is that electron-forge uses the version 4 of jsonfile, while Ipfs uses version 6 of jsonfile. And webpack loads the version 4. How to make electron-forge and webpack loading a specific version of a module, if two versions are present within the npm tree?