Fix esm build to make it work with node#2922
Conversation
|
Hey @wfalcon0x! Thanks for the PR! From your error it looks like the package is actually importing correctly, and instead, this is a runtime error. Specifically, it looks like you may not have loaded the WASM module into the parser before trying to use the Can you try this code? (Make sure to convert it to ESM if you prefer to use that instead) const {CadenceParser} = require("@onflow/cadence-parser")
const fs = require("fs")
const file = fs.readFileSync("./node_modules/@onflow/cadence-parser/dist/cadence-parser.wasm", "binary")
CadenceParser.create(Buffer.from(file, "binary")).then((parser) => {
console.log(parser.parse("pub fun main() {}"))
})Let me know if this solves your issue :) |
|
Hey @jribbink , Thank you for your reply. After converting your CommonJS example to ESM I'm getting exactly the same error. I'm using the cadence-parser from Node.js ES module (ESM), and my code looks the following: There are additional details about the original issue in my previous PR: #2815. I have tested this and my original PR with both in browser and with Node.js. I have also published the solution created in this PR here: It works perfectly with the following code from a Node.js ES module: Please note, package.json "type" value need to be set to "module", which tells Node.js to interpret .js files within that package as using ES module syntax. |
Closes #???
Description
Previous PR #2815 has been provided a solution to build cadence-parser in a way that supports running it in nodejs.
An alternative solution has been merged #2851, which unfortunately was still not working with nodejs and failed with the following error:
This PR provides with a similar approach to #2851, but making sure the solution works both in browser and nodejs.
masterbranchFiles changedin the Github PR explorer