-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't seem to load browser friendly parser #47
Comments
If I load it as it's own file I have access to |
after some battling with this, I was able to make this work in a not too hacky way. // We tell webpack to use the browser friendly package.
wepackConfig.resolve.alias["@solidity-parser/parser"] = "@solidity-parser/parser/dist/index.iife.js";
wepackConfig.module.rules = [
{
// We tell webpack to append "module.exports = SolidityParser;" at the end of the file.
test: require.resolve("@solidity-parser/parser/dist/index.iife.js"),
loader: "exports-loader",
options: {
type: "commonjs",
exports: "single SolidityParser",
},
},
...wepackConfig.module.rules
];
if (isEnvDevelopment) {
// Had some issues on development server with this strategy but works on production.
wepackConfig.module.noParse = /@solidity-parser\/parser/;
} |
Ideally the browser output would be UMD instead of an IIFE, but sadly |
any updates so far? |
@aquiladev sorry, no. I think there are some manual shenanigans that I could do; if this is blocking something important for you I can try to do it one of these days. |
the issue crashed remix sol2uml plugin, I'm thinking to revert it to previous version |
@aquiladev Oh, that sucks. Are you on telegram? Can you DM me? |
I am working on a project that runs purely on browser and I wasn't able to load this package. With a little bit of debugging I found the following code was the cause of the problem in if (typeof BROWSER !== "undefined") {
module.exports = require('./antlr/Solidity.tokens')
} else {
module.exports = require('fs')
.readFileSync(require('path').join(__dirname, './antlr/Solidity.tokens'))
.toString()
} For some reason, if (typeof window !== "undefined") {
module.exports = require('./antlr/Solidity.tokens')
} else {
module.exports = require('fs')
.readFileSync(require('path').join(__dirname, './antlr/Solidity.tokens'))
.toString()
} With this change, everything worked flawlessly. Now I need to mention that I am pretty new to whole Typescript, bundler stuff so maybe what I did was unnecessary or unrelated to the issue raised here. But still, I wanted to share it here in case it might help someone. |
In webpack (>5?) you can skip the
You can also get past
|
I also have this problem in AWS lambda environment
|
this is how // use the parser already included in the app
const parser = (window as any).SolidityParser |
AWS Lambda is not a browser environment, therefore window is not defined. I tried to load the iife file from node modules, but it returned an empty SolidityParser object. In the end, I included the antlr folder in my uploaded zip file. I needed to configure my build so this folder is copied. |
could you have used |
thank you! this worked perfectly for me. should this be considered the official solution? imo the README should reflect this. |
Hi @hananbeer, now that I've been more involved with this codebase and started actively improving it, I will see what I can do to improve and fix this one thing so no extra Webpack configuration should be necessary. |
setting although it isn't iife, it works in browser. I'm not sure what the implications are. I think if someone wants to use iife then they won't have the import issue to begin with. edit: I see now you committed a UMD version, whatever that is. JS-soup. 🤷 |
If trying to load the browser friendly parser I get an empty object.
The text was updated successfully, but these errors were encountered: