Git Product home page Git Product logo

Comments (8)

MWFIAE avatar MWFIAE commented on September 3, 2024 1

Just a quick note: Erdjs is intended for use in the browser, so it's mostly a webpack/configuration issue.

Will try later to reproduce the problem :)

from mx-sdk-js-core.

MWFIAE avatar MWFIAE commented on September 3, 2024

Ok I have reproduced the error and it seems like __dirname is used in the following files:

https://github.com/ElrondNetwork/elrond-sdk-erdjs/blob/main/src/smartcontracts/wrapper/systemWrapper.ts#L11

https://github.com/ElrondNetwork/elrond-sdk-erdjs/blob/main/src/testutils/wallets.ts#L49

According to nodejs.org its a difference between es modules and commonjs modules.
https://nodejs.org/api/esm.html#esm_differences_between_es_modules_and_commonjs

image

One can also take a look at the issue here:
nodejs/help#2907

So as far as I understood it we should replace all occurences of __dirname with smth like this:
nodejs/help#2907 (comment)

from mx-sdk-js-core.

mrazvanalex avatar mrazvanalex commented on September 3, 2024

Have you done any other changes? I tried this fix and I get

/node_modules/@elrondnetwork/erdjs/out/smartcontracts/wrapper/systemWrapper.js:4:18-31 - Error: export 'fileURLToPath' (imported as 'fileURLToPath') was not found in 'url' (possible exports: Url, format, parse, resolve, resolveObject)

./node_modules/@elrondnetwork/erdjs/out/testutils/wallets.js:4:19-32 - Error: export 'fileURLToPath' (imported as 'fileURLToPath') was not found in 'url' (possible exports: Url, format, parse, resolve, resolveObject)

The thing is....
image
the exported method si right there, I don't understand how it was not found. Tried to rebuild and all and still getting this.

Did it just "work" for you out of the box after making the changes?

from mx-sdk-js-core.

mrazvanalex avatar mrazvanalex commented on September 3, 2024

Fixed it by doing this:

import { URL } from 'url'; 
const __dirname = new URL('.', import.meta.url).pathname;

but instead now I'm getting
Uncaught ReferenceError: exports is not defined

only in the wallet.js file we had to change the __dirname earlier.

Probably it's the same issue where this is not available in an ES module.

from mx-sdk-js-core.

mrazvanalex avatar mrazvanalex commented on September 3, 2024

Thanks @MWFIAE for the later fix.

And in node_modules in @elrondnetwork/erdjs/out/smartcontracts/wrapper/systemWrapper.js

SystemConstants.SYSTEM_ABI_PATH = path_1.default.join(__dirname, "../../../abi");

replaced with

SystemConstants.SYSTEM_ABI_PATH = path_1.default.join(".", "../../../abi");

from mx-sdk-js-core.

andreigiura avatar andreigiura commented on September 3, 2024

Hi, i have setup a git repository with a workaround for using erdjs with angular. https://github.com/andreigiura/angular-erdjs-project , it is not pretty, since i have compiled the browser version of erdjs and paste it in the project, but it work for now, until we will figure it out.

from mx-sdk-js-core.

keyur555 avatar keyur555 commented on September 3, 2024

Hi, i have setup a git repository with a workaround for using erdjs with angular. https://github.com/andreigiura/angular-erdjs-project , it is not pretty, since i have compiled the browser version of erdjs and paste it in the project, but it work for now, until we will figure it out.

Have you guys made any progress on figuring this out?

from mx-sdk-js-core.

andreibancioiu avatar andreibancioiu commented on September 3, 2024

This has been fixed in erdjs 10 (we are currently preparing the release), since the packages causing the issue have been extracted to separate repositories:

As of v10, erdjs does not depend on fs and crypto anymore.

from mx-sdk-js-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.